简体   繁体   English

discord.js:Bot 发送相同的嵌入两次

[英]discord.js: Bot is sending the same embed twice

I programmed my discord bot to reply with a message when i type down a certain command, but for some reason, its sending the same embed twice.我对我的不和谐机器人进行了编程,以便在我输入某个命令时回复一条消息,但由于某种原因,它发送了两次相同的嵌入。 I couldn't figure out why.我想不通为什么。 Here's my code:这是我的代码:

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

It might be running on another terminal.它可能正在另一个终端上运行。 Try restarting your PC or find and close that terminal.尝试重新启动您的 PC 或找到并关闭该终端。

This Code works for me此代码对我有用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM