Duplicate messageUpdate events in sharded bot

I'm receiving duplicate messageUpdate events and I'm not sure why. I have tried storing messageId in redis and checking it before sending message, but still it somehow bypasses it. Is it some sort of retry event? It's kind of similar to a let's say a bump reminder bot Relevant code: messageUpdate.ts
if (utils.invalidCondition(newMessage)) return;
const messageUpdate = new MessageHandler();
const handler = messageUpdate.createHandler(newMessage.interaction!.commandName);
await handler.messageUpdate(oldMessage, newMessage);
if (utils.invalidCondition(newMessage)) return;
const messageUpdate = new MessageHandler();
const handler = messageUpdate.createHandler(newMessage.interaction!.commandName);
await handler.messageUpdate(oldMessage, newMessage);
MessageHandler
export class MessageHandler {
constructor() {
// do nothing.
}

createHandler(commandName: string): CreateHandlerReturnType {
switch (commandName) {
case "x":
return new XHandler();
// ...
}
}
}
export class MessageHandler {
constructor() {
// do nothing.
}

createHandler(commandName: string): CreateHandlerReturnType {
switch (commandName) {
case "x":
return new XHandler();
// ...
}
}
}
XHandler
export class XHandler extends BaseMessageHandler {
async messageUpdate(oldMsg: Message<boolean> | PartialMessage, newMsg: Message<boolean> | PartialMessage): Promise<void> {
if (newMsg.embeds[0].title !== "Something") return;
await newMsg.reply({ content: "Test" })
}
export class XHandler extends BaseMessageHandler {
async messageUpdate(oldMsg: Message<boolean> | PartialMessage, newMsg: Message<boolean> | PartialMessage): Promise<void> {
if (newMsg.embeds[0].title !== "Something") return;
await newMsg.reply({ content: "Test" })
}
4 Replies
d.js toolkit
d.js toolkit3mo 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!
Polar
Polar3mo ago
Discord.js: 14.13.0 Node.js: v20.10.0 on adding some console.logs I found that it's the same shard running the same code twice messageUpdate? When the other bot's embed title edits to "confirm", my bot maps the userId to that action yea I'm sure I didn't add any duplicate listeners. Here's my event registeration code:
for await (const dir of botEventFiles) {
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const dynamic = dynamicImport<new () => IEvent>(async () => import(pathToFileURL(dir.fullPath).href));
const resolved = container.resolve<IEvent>((await dynamic()).default);
events.set(resolved.eventName, resolved);
if (resolved.once) {
client.once(
resolved.eventName as keyof ClientEvents,
(...args: Parameters<IEvent["execute"]>): void =>
resolved.execute(...args),
);
} else if (resolved.rest) {
client.rest.on(
resolved.eventName as keyof RestEvents,
(...args: Parameters<IEvent["execute"]>): void =>
resolved.execute(...args),
);
} else {
client.on(
resolved.eventName as keyof ClientEvents,
(...args: Parameters<IEvent["execute"]>): void =>
resolved.execute(...args),
);
}
}
for await (const dir of botEventFiles) {
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const dynamic = dynamicImport<new () => IEvent>(async () => import(pathToFileURL(dir.fullPath).href));
const resolved = container.resolve<IEvent>((await dynamic()).default);
events.set(resolved.eventName, resolved);
if (resolved.once) {
client.once(
resolved.eventName as keyof ClientEvents,
(...args: Parameters<IEvent["execute"]>): void =>
resolved.execute(...args),
);
} else if (resolved.rest) {
client.rest.on(
resolved.eventName as keyof RestEvents,
(...args: Parameters<IEvent["execute"]>): void =>
resolved.execute(...args),
);
} else {
client.on(
resolved.eventName as keyof ClientEvents,
(...args: Parameters<IEvent["execute"]>): void =>
resolved.execute(...args),
);
}
}
How can the code be better? I thought the standard factory design pattern was good enough I see oh. I fixed it and just forgot to update in the other parts of the code. I've updated the message that should be more readable
Polar
Polar3mo ago
No description
Polar
Polar3mo ago
and also console.log(client.listenerCount("messageUpdate"))
I get 1 the addReminder function is called for the exact same messageId hmm that could be possible, let me check if that's the case That indeed was the case, there's apparently a new field in embeds called content_scan_version, oldMessage and newMessage are same with content_scan_version being 0 for oldMessage and content_scan_version being 1 in newMessage Thank you very much for narrowing down the issue, appreciate it