可以做这样的事吗?据我了解,你应该使用if (enabled == true)
但我不知道怎么做。
您可以使用全局变量(例如client.isPaused
)并检查其值。查看下面的代码片段:
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...');
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)