Duplicate Message Send

Hello, I've been having an issue with a channel.send() call occasionally resulting in a message being sent multiple times. Node.js: v18.12.1 Discord.js: v14.9.0 OS: Ubuntu 20.04 LTS Code:
async function sendMessage(
channelId: Snowflake,
guildId: Snowflake,
client: Client,
data: data,
timestamp: number,
roles: [Snowflake?],
) {
const guildroles = roles.length ? [...new Set(roles)] : roles;
if (data) {
const embed = new EmbedBuilder()
.setColor('#0e48b8')
.setTitle(data.name)
.setDescription(data.description)
.setTimestamp(timestamp);

(client.guilds.cache.get(guildId)?.channels.cache.get(channelId) as TextBasedChannel)
.send({
content: guildroles?.length ? guildroles.map((g) => `<@&${g}>`).join(' ') : '',
embeds: [embed],
})
.then((m) => console.log(process.pid, '[Discord.js]', 'Sent data to channel:', m.channelId))
.catch((e: any) => {
console.log(e);
});
}
}
async function sendMessage(
channelId: Snowflake,
guildId: Snowflake,
client: Client,
data: data,
timestamp: number,
roles: [Snowflake?],
) {
const guildroles = roles.length ? [...new Set(roles)] : roles;
if (data) {
const embed = new EmbedBuilder()
.setColor('#0e48b8')
.setTitle(data.name)
.setDescription(data.description)
.setTimestamp(timestamp);

(client.guilds.cache.get(guildId)?.channels.cache.get(channelId) as TextBasedChannel)
.send({
content: guildroles?.length ? guildroles.map((g) => `<@&${g}>`).join(' ') : '',
embeds: [embed],
})
.then((m) => console.log(process.pid, '[Discord.js]', 'Sent data to channel:', m.channelId))
.catch((e: any) => {
console.log(e);
});
}
}
Upon this function executing, I receive the following logs:
2544499 [Undici] Making request to: /api/v10/channels/1125283603702632531/messages
2544499 [Undici] Making request to: /api/v10/channels/1125283603702632531/messages
2544499 [Undici] Making request to: /api/v10/channels/1125283603702632531/messages
2544499 [Discord.js] Posted to /channels/1125283603702632531/messages
2544499 [Discord.js] Sent data to channel: 1125283603702632531
2544499 [Undici] Making request to: /api/v10/channels/1125283603702632531/messages
2544499 [Undici] Making request to: /api/v10/channels/1125283603702632531/messages
2544499 [Undici] Making request to: /api/v10/channels/1125283603702632531/messages
2544499 [Discord.js] Posted to /channels/1125283603702632531/messages
2544499 [Discord.js] Sent data to channel: 1125283603702632531
First 3 logs are requests made by undici, 4th log is from a client.rest response event 5th log is from the .then() method called on the promise returned by channel.send() It appears that despite my function only being called once, the message is being sent multiple times. If anyone has an idea as to what could cause this, please let me know.
4 Replies
d.js toolkit
d.js toolkit15mo 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!
MD
MD15mo ago
I created similar thread here: https://discord.com/channels/222078108977594368/1137513755840872449 try to add this to your code
<Client>.rest.on(RESTEvents.Response, console.dir);
<Client>.rest.on(RESTEvents.Response, console.dir);
if you get "retries" value not equal to 0 in duplicated message, probably you have the same issue
.demonslayer
.demonslayerOP15mo ago
These are the timestamps for each of the messages, in ms: 1693526700252 1693526715149 1693526730300 Approximately 15 seconds between each send I do get a value greater than 0 for retries in cases where duplicate messages are sent.
LeStyloBleu
LeStyloBleu15mo ago
Yeah we have the same issue for sure
Want results from more Discord servers?
Add your server