When the condition of emoji.id is met === '847502744176820256' is fulfilled
, does not stop sending message in consola or channel, how do I stop it?
const { Client, Intents } = require("discord.js-selfbot");
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS],
});
let token = "";
client.on('ready', () => {
console.log('Ok');
});
client.on('messageReactionAdd', (messageReaction, user) => {
const { message, emoji } = messageReaction;
if(emoji.id === '847502744176820256'){
setTimeout(function(){
console.log("reaction ADD")
message.channel.send("ok")
message.react(':wleft:847502744176820256')
}, 350);
}
});
Your code, whenever a reaction is added to a message, checks for the condition that the emote being added is 847502744176820256. If that condition is met, you send your console and Discord messages, and then react with the emote 847502744176820256. By reacting, you trigger the reaction added event. The emote you added has the same ID, so it meets the condition. Thus, it sends the messages again, and reacts again with the same ID. And that meets the condition again. And the cycle continues.
This is a classic infinite loop.
This is why it is usually good practice to ignore events triggered by bots, including your own. You do not want your bot to trigger its own event handler. Here's how you could do that:
if(emoji.id === '847502744176820256' && !user.bot){
setTimeout(function(){
console.log("reaction ADD")
message.channel.send("ok")
message.react(':wleft:847502744176820256')
}, 350);
}
Alternatively, if you want to accept input from other bots but not your own, you could check specifically for your bot's ID instead of checking if the user is a bot.