BenW
BenW
DIAdiscord.js - Imagine a bot
Created by BenW on 10/26/2023 in #djs-questions
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!
6 replies
DIAdiscord.js - Imagine a bot
Created by BenW on 9/20/2023 in #djs-questions
Modals
const modal = new ModalBuilder({
customId: 'customDurationModal',
title: 'Custom Duration',
});

const customDurationInput: TextInputBuilder = new TextInputBuilder()
.setCustomId('duration')
.setPlaceholder('1')
.setMinLength(1)
.setMaxLength(4)
.setRequired(true);

const actionRow = new ActionRowBuilder<TextInputBuilder>().addComponents(customDurationInput);

console.log(actionRow);

console.log(customDurationInput);

modal.addComponents(actionRow);

console.log(interaction);

console.log('custom');

console.log(modal);
await interaction.showModal(modal);
const modal = new ModalBuilder({
customId: 'customDurationModal',
title: 'Custom Duration',
});

const customDurationInput: TextInputBuilder = new TextInputBuilder()
.setCustomId('duration')
.setPlaceholder('1')
.setMinLength(1)
.setMaxLength(4)
.setRequired(true);

const actionRow = new ActionRowBuilder<TextInputBuilder>().addComponents(customDurationInput);

console.log(actionRow);

console.log(customDurationInput);

modal.addComponents(actionRow);

console.log(interaction);

console.log('custom');

console.log(modal);
await interaction.showModal(modal);
Trying to add a modal but I get the below error, any ideas?
[Event: interactionCreate] [Command Error] ValidationError > s.nativeEnum(T)
Expected the value to be a string or number

Received:
| undefined
[18:19]
The error is happening when I try to call await interaction.showModal(modal)
[Event: interactionCreate] [Command Error] ValidationError > s.nativeEnum(T)
Expected the value to be a string or number

Received:
| undefined
[18:19]
The error is happening when I try to call await interaction.showModal(modal)
7 replies
DIAdiscord.js - Imagine a bot
Created by BenW on 8/28/2023 in #djs-questions
Max number of command registrations
Hi, I am working on transitioning my bot to a slash commands. I see there is a limit on how many times we can register commands a day. How do you get around this in development? For example if I have 10 commands, and go through 20 iterations of a single command during development I would run out of registrations. Am I expected to only register one command at a time? What if I'm simply pushing a lot of commands into my bot on a certain day? Any help on best practices here would be great
21 replies
DIAdiscord.js - Imagine a bot
Created by BenW on 9/7/2022 in #djs-questions
Not registering events
Hello! I am having an issue where events (in this case, guildBanAdd) doesn't always register. When I am testing in my own server, ban logging works 100% of the time. When in production, it doesn't work 100% of the time (but has been confirmed working intermittently). I can only assume that in production multiple events are being fired quickly and it gets missed, or is slow? I am not sure why it is not always registering in production. Further to this, when someone is banned later on and the event is registered by the bot, it will post the log, but the audit log conflicts, almost like it has grabbed the event from the earlier ban and newer ban. I know it conflicts as I have a check for if the ban executor matches the executor in the audit log. If they don't it just sends a generalised log with an 'Audit log incomplete' message to not send wrong information. I hope this makes sense. We rarely use a 'discord ban' and usually use our 'bot ban'. This only affects 'discord bans' as we log through our bot when banning with it. The only time this affects a 'bot ban' is when a 'discord ban' has been used before it and it seems like it registers both events. it's quite confusing so not sure best how to explain.
7 replies