Polar
Polar
DIAdiscord.js - Imagine an app
Created by Polar on 3/27/2024 in #djs-questions
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" })
}
15 replies
DIAdiscord.js - Imagine an app
Created by Polar on 11/14/2023 in #djs-questions
Scheduled message causes duplicate messages in sharded app
I have a sharded bot that sends reminders, but sometimes the bot sends duplicate messages. I'm not sure how to prevent this. I've tried: - Storing the messageId in redis for 10 mins after successfully sending a message, then checking if redis has the messageId before sending, if not found, I send the message - Implemented mutex I've observed duplicate reminders are being sent when too many messages are sent Yet duplicate reminders are being sent. I'm not sure if this is the correct, what's the standard way to do reminders in a sharded bot?
7 replies
DIAdiscord.js - Imagine an app
Created by Polar on 4/30/2023 in #djs-questions
Discord.js Error
I get this error randomly and the bot crashes
Error [TypeError]: Cannot read properties of null (reading 'id')
at ShardClientUtil._handleMessage (C:\Users\e\Desktop\bot\node_modules\discord.js\src\sharding\ShardClientUtil.js:193:48)
at process.emit (node:events:513:28)
at emit (node:internal/child_process:937:14)
at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
Error [TypeError]: Cannot read properties of null (reading 'id')
at ShardClientUtil._handleMessage (C:\Users\e\Desktop\bot\node_modules\discord.js\src\sharding\ShardClientUtil.js:193:48)
at process.emit (node:events:513:28)
at emit (node:internal/child_process:937:14)
at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
17 replies
DIAdiscord.js - Imagine an app
Created by Polar on 7/21/2022 in #djs-questions
Button not displaying
6 replies
DIAdiscord.js - Imagine an app
Created by Polar on 7/19/2022 in #djs-questions
Getting original userID of slash command via Button Interaction
Hey, so I'm using a button Handler. But everyone can interact with the button. How do I restrict the button to be usable by the user who ran the slash command from which the button originated? (I use the interactionCreate event to reply to the buttons, so I can only get the buttonInteraction). I don't wanna use db
36 replies
DIAdiscord.js - Imagine an app
Created by Polar on 7/6/2022 in #djs-questions
How does giveaway auto end
Hello, I'd like to know which event do giveaway bots use for the giveaways to auto end. Is there an event which does a check every second?
5 replies