【问题标题】:discord.js: Bot is sending the same embed twicediscord.js:机器人两次发送相同的嵌入
【发布时间】:2021-01-09 20:52:12
【问题描述】:

我对我的不和谐机器人进行了编程,以便在我输入某个命令时回复一条消息,但由于某种原因,它发送了两次相同的嵌入。我不知道为什么。这是我的代码:

const Discord = require('discord.js');
const client = new Discord.Client();

client.on("message", message => {

     if (message.content.toLowerCase().startsWith(prefix + "clear")) {
        message.channel.messages.fetch({limit: 100}).then(messages => {         
        message.channel.bulkDelete(messages)});

        const deleteEmbed = new Discord.MessageEmbed()
        .setColor('#ffd6d6')
        .setTitle('Bot has completed the action of clearing messages.\n')
        .setDescription(`Bot has deleted some messages.`)
        client.channels.cache.get('757945678772305921').send(deleteEmbed); 
    }
}); 

【问题讨论】:

    标签: javascript node.js discord.js


    【解决方案1】:

    它可能正在另一个终端上运行。尝试重新启动您的 PC 或找到并关闭该终端。

    【讨论】:

      【解决方案2】:

      此代码适用于我

      client.on('message', message => {
        const args = message.content.slice(prefix.length).split(/ +/);
        const command = args.shift().toLowerCase();
        if (!message.content.startsWith(prefix) || message.author.bot) return;
        if (command.includes('blacklist')) {
          message.react('?')
          const blacklistEmbed = new Discord.MessageEmbed()
            .setColor('#ffd6d6')
            .setTitle('!Blacklist\n')
            .setDescription('Private Messages\nCheck Your PMs For More Information')
          message.channel.send(blacklistEmbed)
          const blacklist2Embed = new Discord.MessageEmbed()
            .setColor('#ffd6d6')
            .setTitle('!Blacklist\n')
            .addField("Banned Words Are;", profanities)
          message.author.send(blacklist2Embed)
        }
      });
      

      【讨论】:

        猜你喜欢
        • 2020-09-15
        • 2021-05-08
        • 2019-09-20
        • 1970-01-01
        • 1970-01-01
        • 2023-03-30
        • 2020-06-29
        • 2021-07-22
        • 2022-01-24
        相关资源
        最近更新 更多