Skip to content

Commit

Permalink
Fixed webhooks using the wrong delete command and added better error …
Browse files Browse the repository at this point in the history
…handling
  • Loading branch information
-ˏˋ Maple ˊˎ committed Aug 15, 2023
1 parent 498c808 commit d43abb4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
9 changes: 9 additions & 0 deletions src/bot/events/InteractionCreate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//InteractionCreate event
const { Events } = require('discord.js');
const { getLocalization } = require('../../localizations/localizations.js');

module.exports = {
name: Events.InteractionCreate,
Expand All @@ -16,6 +17,14 @@ module.exports = {
await command.execute(interaction);
}
} catch (error) {
if (error.code === 50013) {
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: getLocalization("common:errors.missingPermission", interaction.locale), ephemeral: true });
} else {
await interaction.reply({ content: getLocalization("common:errors.missingPermission", interaction.locale), ephemeral: true });
}
}

console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
Expand Down
2 changes: 1 addition & 1 deletion src/bot/interactions/commands/QuickTranslate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {

async execute(interaction) {
if (!interaction.targetMessage.content) {
await interaction.reply({ content: getLocalization("context:translate.noText", interaction.locale), ephemeral: true});
await interaction.reply({ content: getLocalization("common:errors.noText", interaction.locale), ephemeral: true});
// wait 5 seconds and delete the message
return setTimeout(() => {
return interaction.deleteReply();
Expand Down
6 changes: 3 additions & 3 deletions src/bot/interactions/commands/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ module.exports = {
await response.awaitMessageComponent({ filter: collectorFilter, time: process.env.DELETE_BUTTON_TIMEOUT*1000 });
//delete the webhook message
for (let i = 0; i < sentMessages.length; i++) {
sentMessages[i].delete();
webhook.deleteMessage(sentMessages[i].id);
}
} catch (e) {
if (e instanceof DiscordjsErrorCodes.InteractionCollectorError) {
console.log(e);
if (!(e instanceof DiscordjsErrorCodes.InteractionCollectorError)) {
throw e;
}
}
//remove the delete message
Expand Down
7 changes: 5 additions & 2 deletions src/localizations/configs/English.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"context": {
"translate": {
"name": "Translate",
"footer": "pro tip: this feature uses the language defined in your discord settings.",
"noText": "This message is empty!"
"footer": "pro tip: this feature uses the language defined in your discord settings."
}
},
"common": {
Expand All @@ -37,6 +36,10 @@
"name": "from",
"description": "The language to translate from."
}
},
"errors": {
"noText": "This message is empty!",
"missingPermission": "oops! I don't have permission to do that, please check that you've used the correct invite link!"
}
}
}
7 changes: 5 additions & 2 deletions src/localizations/configs/French.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"context": {
"translate": {
"name": "Traduire",
"footer": "info: cette fonctionnalité utilise le langage défini dans vos paramètres discord",
"noText": "Ce message est vide!"
"footer": "info: cette fonctionnalité utilise le langage défini dans vos paramètres discord"
}
},
"common": {
Expand All @@ -37,6 +36,10 @@
"name": "depuis",
"description": "La langue du message."
}
},
"errors": {
"noText": "Ce message est vide !",
"missingPermission": "oups! Je n'ai pas la permission de faire ça ! Veuillez vérifier que vous avez utilisé le bon lien d'invitation."
}
}
}

0 comments on commit d43abb4

Please sign in to comment.