问题
I want my bot to respond once to a command such as .on. However, it responds multiple times per input:
The code is:
client.on('message', message =>{
if(message.content === '.on'){
message.channel.sendMessage('Testing Bot is now Online, Greetings, ' + message.author.username);
}
If anyone could point me in the right direction to make the bot respond once that would be great.
回答1:
sendMessage is deprecated. Try using send instead.
client.on('message', message => {
if(message.content === '.on') {
message.channel.send('Testing Bot is now Online, Greetings, ' + message.author.username);
}
}
Also, if this still causes issues consider checking the id/content of the message event as well as the returned promise to make sure you didn't make a mistake elsewhere. It'll be obvious very quickly what's going on. That'd be:
client.on('message', message => {
if(message.content === '.on') {
console.log('Received #' + message.id + ': ' + message.content);
message.channel.send('Testing Bot is now Online, Greetings, ' + message.author.username)
.then(message => console.log('Sent #' + message.id + ': ' + message.content))
.catch(console.error);
}
}
回答2:
I'm late, but i thik you had multiplie instances of bot running at the same time
回答3:
Try to change the token (work for me)
来源:https://stackoverflow.com/questions/43772293/discord-bot-responds-multiple-times-for-one-event