Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

javascript - My DC Bot send a message twice or more times

I tried to make a simple welcomer bot, but I ran into an issue, sometimes the bot send a welcome message twice or more times, and I can't figure out why it's happening. Here's my code and a picture of the bug.

Code:

client.on("guildMemberAdd", async (member) => {
    let welcomeChannel = member.guild.channels.cache.find(channel => channel.name === "??új-tagok");
    let welcomer = new Discord.MessageEmbed()
    .setTitle(`${member.guild.name}`)
    .setColor("#FF8A00")
    .setThumbnail("https://i.redd.it/f1u2wf28nqn21.jpg")
    .setDescription(`D-${getRandomInt(0, 9)}${getRandomInt(0, 9)}${getRandomInt(0, 9)}${getRandomInt(0, 9)}, más néven ${member.user.username} csatlakozott a szerverre!`);
     welcomeChannel.send(welcomer);
});

Picture: https://imgur.com/a/MgIt6oD


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here are some ways that could assist in fixing this issue:

Check you have the client started only once

Make sure you don't have two terminals running at once. This also includes certain bot hosting, where both the terminal and the host are running at once.

Regenerate the token

While this should be your last result, even though it's not that of a big deal, sometimes bot token regenerating could fix the issue, although as I said, keep it as a last result.

Killing the entire process

You can try to completely kill the process by using the Client.destroy() function inside of your code or pressing cmd + Z on your keyboard inside of the terminal.

enter image description here

Finally, just try restarting.

Try restarting either your coding platform or computer as a whole, it could assist sometimes in giving the client a quick refresh and might just do the job. It helped me countless of times in the past.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...