Strange behavior with selectively sending multiple embeds

I have a welcome message embed. The issue is that the embed will sometimes send 3 times in the welcome channel, but consistently only send once in the log channel, even though they're a part of the same event file. I have no idea how this could happen. Event file:
import { ChannelType, Events, GuildMember } from 'discord.js';
import { Client } from '../Structures/Client';
import { EmbedBuilder } from '../Structures/EmbedBuilder';

export default {
event: Events.GuildMemberAdd,
async run (client: Client, member: GuildMember) {
const channel = await member.guild.channels.fetch(client.config.welcomeChannel);

if (channel.type !== ChannelType.GuildText) return;

const embed = new EmbedBuilder({ color: 'green' })
.setTitle(...)
.setThumbnail(...)
.setDescription(...);

await channel.send({ content: `<@${member.id}>`, embeds: [embed] });

const logChannel = await member.guild.channels.fetch(client.config.guildLogChannel);

if (logChannel.type !== ChannelType.GuildText) return;

const logEmbed = new EmbedBuilder({ color: 'green', author: member.user })
.setTitle('Member Joined')
.setDescription(`<@${member.id}>\n\`${member.displayName}\` (${member.id}) has joined the server.`)
.setThumbnail(member.user.displayAvatarURL())
.setTimestamp();

await logChannel.send({ embeds: [logEmbed] });
}
}
import { ChannelType, Events, GuildMember } from 'discord.js';
import { Client } from '../Structures/Client';
import { EmbedBuilder } from '../Structures/EmbedBuilder';

export default {
event: Events.GuildMemberAdd,
async run (client: Client, member: GuildMember) {
const channel = await member.guild.channels.fetch(client.config.welcomeChannel);

if (channel.type !== ChannelType.GuildText) return;

const embed = new EmbedBuilder({ color: 'green' })
.setTitle(...)
.setThumbnail(...)
.setDescription(...);

await channel.send({ content: `<@${member.id}>`, embeds: [embed] });

const logChannel = await member.guild.channels.fetch(client.config.guildLogChannel);

if (logChannel.type !== ChannelType.GuildText) return;

const logEmbed = new EmbedBuilder({ color: 'green', author: member.user })
.setTitle('Member Joined')
.setDescription(`<@${member.id}>\n\`${member.displayName}\` (${member.id}) has joined the server.`)
.setThumbnail(member.user.displayAvatarURL())
.setTimestamp();

await logChannel.send({ embeds: [logEmbed] });
}
}
Handler:
private initListeners(): this {
const listeners = fs.readdirSync(path.join(__dirname, '../Listeners'));
for (const listenerFile of listeners) {
const listener = require(path.join(__dirname, '../Listeners', listenerFile)).default as Listener;
this.on(listener.event, (...args) => listener.run(this, ...args));
}
return this;
}
private initListeners(): this {
const listeners = fs.readdirSync(path.join(__dirname, '../Listeners'));
for (const listenerFile of listeners) {
const listener = require(path.join(__dirname, '../Listeners', listenerFile)).default as Listener;
this.on(listener.event, (...args) => listener.run(this, ...args));
}
return this;
}
11 Replies
d.js toolkit
d.js toolkit6mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Finbar
FinbarOP6mo ago
Only 1 listener
No description
GitHub
GitHub6mo ago
:issue_open: #10301 in discordjs/discord.js by wisienak opened <t:1716698508:R> Bot send embed messages twice or even triple times after being not used for a while
NyR
NyR6mo ago
Please read through this issue for the solution, you may need to provide nonce
Finbar
FinbarOP6mo ago
interesting thankyou Would just this be fine?
const nonce = SnowflakeUtil.generate().toString();
await channel.send({ content: `<@${member.id}>`, embeds: [embed], nonce });
const nonce = SnowflakeUtil.generate().toString();
await channel.send({ content: `<@${member.id}>`, embeds: [embed], nonce });
When I try to implement enforceNonce: true I get a typescript error: TS2353: Object literal may only specify known properties, and  enforceNonce  does not exist in type  MessagePayload | MessageCreateOptions 
Finbar
FinbarOP6mo ago
discord.js
discord.js
discord.js is a powerful Node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.
NyR
NyR6mo ago
Update to latest which is v14.15.3
Finbar
FinbarOP6mo ago
would this not work on the older version? it seems stupid to have to supply a boolean enabling something instead of just checking if it was supplied
NyR
NyR6mo ago
Probably, enforceNonce tells discord to check for nonce, idk if they do by default, you can try it out and see if works
Finbar
FinbarOP6mo ago
¯\_(ツ)_/¯ ill try keeping it on 14.14.1 for now thanks for the help
Want results from more Discord servers?
Add your server