i am creating a small discord bot. when setting up the commands that start after the client is on, one of them, which is setTimeout, does nothing.
here’s a part of the code:
client.once('ready', () => {
console.log('the bot is online!');
});
client.on('messageCreate', (message) => {
if (message.content === 'ping') {
message.reply({
content: 'pong',
})
}
setTimeout(client.channels.cache.get('<channel ID>').send('time is out'), 3000);
});
no error shows, just nothing happening 🙁 if you know what’s wrong, please let me know
>Solution :
First of all, you’ll need to escape the ‘ character in your "time’s out" string like so:
'time\'s out'
Second of all, you have to pass a callback to setTimeout as the first parameter so you need to use an arrow function like so.
setTimeout(() => {client.channels.cache.get('<channel ID>').send('time\'s out')}, 3000);