嵌入消息循环不会停止

时间:2019-05-30 13:58:48

标签: discord.js

如果我键入pingtest,那么我的机器人就会一次又一次地发送嵌入消息(无限循环)

if (message.content='pingtest') {
    message.channel.send({embed: {

            color: 000000,
            author: {
              name: client.user.username,
              icon_url: client.user.avatarURL
            },
            title: "A RAID HAS BEGUN (for the Dark Side)",
            description: "",
            fields: [{
                name: "------------------------------",
                value:"Write !raid to enter."
              }

            ],
            footer: {
              icon_url: client.user.avatarURL,
            }
          }
        });
}

2 个答案:

答案 0 :(得分:0)

问题:在您的if语句中,您正在使用assignment operator=
解决方案:使用equality operator(即===)来比较message.content
说明:现在,您的代码是设置 message.content,而不是比较。这意味着无论message.content是什么,您都会收到“ pingtest”的预期结果。至于循环,我猜想您在消息事件中允许来自其他漫游器的消息。因此,当机器人看到自己的消息时,它将再次触发相同的错误代码,从而产生连锁反应。
修订后的代码:

if (message.author.bot) return; // bots will no longer trigger a command

if (message.content === 'pingtest') { // comparing message.content with ===
  // < your code for the 'pingtest' command >
}

答案 1 :(得分:0)

您需要嵌入

realValue()
相关问题