如何使机器人不响应自身,但仍响应其他机器人



我又回到了与这个不和谐机器人一起工作的磨练中,在这一点上,我已经对她如此依恋,以至于我决定为她制作几个伴侣机器人,让她可以在小对话中来回回应!问题是,为了让她与其他机器人交谈,我只是删除了这一行代码......

if (message.author.bot) return;

。事实证明,这产生了一些我应该预料到的影响,当我提起她的rei!help命令时,它引发了她的每一个其他命令......

除了上面的代码之外,我可以使用其他方法,以便她只不回复自己的消息?我已经看到(message.userID === bot.userID)使用过,但对于我的机器人来说,如果我将该代码复制粘贴到其中,它只是锁定并且不会响应任何内容。它也不会显示错误消息...

任何帮助不胜感激,谢谢!

编辑:这里代码行周围的内容!

///constants and dependencies above here
//console log
bot.on('ready',() => {
   console.log('Up and running!!!');
});
//set 'playing' to
bot.on('ready', () => {
 bot.user.setActivity('hehe clairvoyance time')
});
//bot stuff
bot.on('message', message => {
  // heres the stuff so reibot doesnt go ham every time someone does rei!help
  if (message.author.bot) return;
///all commands below here

您可以检查作者的 ID 是否是客户端的 ID。这样,它将忽略自己(并且仅自己(发送的任何消息。

if (message.author.id === client.user.id) return;

最新更新