I made a bot blacklist but the bot gets stuck in a loop when anyone uses anything

Viewed 155

I made a blacklist for the bot, it "works", it blocks the blacklisted user from using the bot but ended up causing a loop and the blacklisted message to get spammed, both when a blacklisted user uses it and when someone that isnt on the blacklist uses it

heres the code

client.on('message', async message => {

    let blacklist = new Discord.MessageEmbed()
  .setColor("#e31212")
  .setDescription(
    "ERROR: You are not allowed to use this bot | Reason: BLACKLISTED"
  );
var blacklistids = ["402639792552017920", "711957885722296360"];
if (blacklistids.includes(message.author.id)) {
    message.channel.send(blacklist).then(msg => {
        msg.delete({ timeout: 3000 })
      })
}
// Rest of the code
})
2 Answers

Your code seems correct - but by how you've described it, it would seem to me your code is wrapped in a loop somewhere else. Have you tried creating another client.on() with different conditions to see if those messages also get looped/spammed?.

This is something that can easily occur, especially if you are a beginner.

EDIT: you are however missing }); at the end of your client.on() declaration.

It looks like one of your IDs in the array might be the bot's ID... if this is the case, you might also want to have a if(message.author.bot) return after the client.on(...

Related