My bot sends the same message several times in private

Viewed 45

I have set my bot to send each message after sending it a private message, code:

client.on('message', async (message) => {
  if (message.author.bot) return;
  if(message.channel.type === 'dm') {
    const dmembed = new DiscordJS.MessageEmbed()
  .setTitle(`New Mail Colllected!`)
  .setThumbnail(message.author.displayAvatarURL({dynamic: true}))
  .setColor('BLUE')
  .setTimestamp()
  .setDescription(`**User:** ${message.author.tag} (\`${message.author.id}\`)\n**Date:** ${require("moment")(Date.now()).format("LLLL")}\n\n**Mail Content:** \`\`\`\n${message.content}\n\`\`\``)
  .setFooter(`ID: ${message.author.id}`)
  const dmchannel = client.channels.cache.get('851481340696068156')
  dmchannel.send(dmembed)
  }
})

The problem is that the bot is repairing the room several times, I tried to fix it but it does not work so well, I would be happy to help

1 Answers

Hello OF3K

I don't see anything wrong with the code, you are filtering out so it won't respond to any bots :) My guess would be that you have multiple instances of a terminal open. If you are using vs code chances are your terminal will look like this: Showing a picture of vscode terminal window

As you can see, I have 3 instances of node open, you would want to close everyone but one.

Hope this helps :)

Related