Discord机器人针对一个事件多次响应 [英] Discord bot responds multiple times for one event

查看:93
本文介绍了Discord机器人针对一个事件多次响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的机器人一次响应诸如 .on 之类的命令。但是,它会对每个输入多次响应:

I want my bot to respond once to a command such as .on. However, it responds multiple times per input:

代码是:

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.

推荐答案

sendMessage 已弃用。尝试使用 发送

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);
    }
}

此外,如果仍然引起问题,请考虑检查ID消息事件的/ content以及返回的承诺,以确保您没有在其他地方犯错。很快就会知道发生了什么。可以是:

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);
    }
}

这篇关于Discord机器人针对一个事件多次响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆