I'm trying to make the setInterval clear when a user types in the off command, how would I go about doing this? Basically, the user types the on command then then turn it off using the off command. This is a snippet of what I currently have. 
bot.on('message', (message) => {
    if (message.content.startsWith(prefix + 'on')) {
        var check = setInterval(test, 5000); 
    } else if (message.content.startsWith(prefix + 'off')) {
        clearInterval(test);
    }
    function test() {
    console.log('hello');
    }
}
 
    