Discord bot responds multiple times for one event

為{幸葍}努か 提交于 2019-12-24 01:58:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!