【问题标题】:Embed message loop doesnt stop嵌入消息循环不会停止
【发布时间】:2019-05-31 20:26:07
【问题描述】:

如果我输入 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,
            }
          }
        });
}

【问题讨论】:

  • 发送带有“pingtest”的消息是否触发循环,或者发送任何消息是否触发?
  • 您可以添加更多代码吗?
  • @Jamesm 有任何消息
  • 你能帮我试试 if (message.content ==='pingtest') 看看是否有效吗?

标签: discord.js


【解决方案1】:

问题:在您的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 >
}

【讨论】:

    【解决方案2】:

    你需要嵌入

    if(message.content.startsWith('pingtest'))
       let embed = new Discord.Embed
           .setColor('color')
           .setTitle('title')
           .setAuthor(`${client.user.username}`)
           .setDescreption('Descreption')
           .addField('Field)
          message.channel.send(embed)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-24
      • 2015-12-30
      相关资源
      最近更新 更多