Interaction already replied on bot restart

Hello, I am getting the interaction already replied when my bot re-deploys after changes are pushed to github. It seems that two instances of the bot are probably running for a split second causing one bot to reply and the other to error out as the interaction has been replied to. This only happens if I run a command as soon as it's deployed - if I wait a little its fine (presumably the other bot is dead by then) I am using Digital Ocean. See the code below for termination:
const handleTermination = async () => {
Logger.info('Terminating bot...');
try {
client.removeAllListeners();
await closeMongooseConnection();
await client.destroy();
Logger.info('Cleanup complete. Exiting...');
process.exit(0);
} catch (error) {
Logger.error('Error during termination:', error);
process.exit(1);
}
};

process.on('SIGINT', handleTermination);
process.on('SIGTERM', handleTermination);
const handleTermination = async () => {
Logger.info('Terminating bot...');
try {
client.removeAllListeners();
await closeMongooseConnection();
await client.destroy();
Logger.info('Cleanup complete. Exiting...');
process.exit(0);
} catch (error) {
Logger.error('Error during termination:', error);
process.exit(1);
}
};

process.on('SIGINT', handleTermination);
process.on('SIGTERM', handleTermination);
I see a SIGTERM signal should be sent by DO but I don't see any of my logging in the runtime logs, the bot just restarts. Do I need to change anything in my bot code? Or change my DO setup? Any help appreciated!
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!
DaveY
DaveY15mo ago
I’ve never needed to use shutdown procedures on D.O. Bots, but if you needed to you could setTimeout the client.login a bit, which would give you a little breathing room.
BenW
BenWOP15mo ago
Ah, so basically delaying the bot logging up by some time? Let the old deployment completley exit Have you're bots been ok then? No overlap in interactions when a new deployment goes live?
DaveY
DaveY15mo ago
Aside from network connectivity issues recently, my bots haven't had that issue. When it kills the process it's gone
Want results from more Discord servers?
Add your server