Is it possible to do such thing? For what I understood you should use if (enabled == true)
but I'm not sure how.
Asked
Active
Viewed 1,856 times
1

Zsolt Meszaros
- 21,961
- 19
- 54
- 57

tom.js
- 232
- 1
- 2
- 13
1 Answers
5
You could use a global variable (e.g. client.isPaused
) and check its value. Check out the code snippet below:
const client = new Client();
const prefix = '!';
// enabled by default
client.isPaused = false;
client.on('message', (message) => {
if (message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
// the only command allowed when bot is paused
if (command === 'unpause') {
if (!client.isPaused)
return message.channel.send(
`The bot is already listening to commands, can't unpause it.`,
);
client.isPaused = false;
return message.channel.send(`The bot is listening to your commands again.`);
}
// if bot is paused, exit so the commands below will not get executed
if (client.isPaused) return;
if (command === 'pause') {
client.isPaused = true;
return message.channel.send(
`The bot is paused. Use \`${prefix}unpause\` to unpause it.`,
);
}
if (command === 'ping') {
return message.channel.send('Pong!');
}
if (command === 'time') {
return message.channel.send(
`The time is ${new Date().toLocaleTimeString()}`,
);
}
});
client.once('ready', () => {
console.log('Bot is connected...');
});

Zsolt Meszaros
- 21,961
- 19
- 54
- 57