Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

setTimeout does nothing (discord.js)

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading