- fix multiple responses to single interaction

This commit is contained in:
Enrico Bühler 2022-09-21 16:24:27 +02:00
parent c018d35e2a
commit 401329bff1
3 changed files with 22 additions and 16 deletions

View File

@ -8,7 +8,8 @@
"private": true,
"scripts": {
"database:migrate": "yarn prisma migrate dev",
"dev": "nodemon --watch './**/*.ts' --exec 'ts-node --esm -r tsconfig-paths/register ./src/index.ts'"
"dev": "nodemon --watch './**/*.ts' --exec 'ts-node --esm -r tsconfig-paths/register ./src/index.ts'",
"start": "ts-node --esm -r tsconfig-paths/register ./src/index.ts"
},
"devDependencies": {
"@types/node": "^18.7.18",
@ -28,4 +29,4 @@
"dotenv": "^16.0.2",
"node-cleanup": "^2.1.2"
}
}
}

View File

@ -32,13 +32,9 @@ export default class DiscordController extends EventEmitter {
async handleInteraction(interaction: Interaction<CacheType>) {
if (interaction.isModalSubmit()) {
await this.handleModalSubmit(interaction);
}
if (interaction.isChatInputCommand()) {
} else if (interaction.isChatInputCommand()) {
await this.handleChatInputCommand(interaction);
}
if (interaction.isButton()) {
} else if (interaction.isButton()) {
await this.handleButton(interaction);
}
}
@ -59,11 +55,13 @@ export default class DiscordController extends EventEmitter {
switch (commandName) {
case "quote":
await this.discordService.handleQuote(interaction);
return;
case "quotemodal":
await this.discordService.handleQuoteModal(interaction);
return;
case "actions":
await this.discordService.handleActions(interaction);
return;
default:
break;
}
@ -75,10 +73,9 @@ export default class DiscordController extends EventEmitter {
switch (customId) {
case "quoteModal":
await this.discordService.handleQuote(interaction);
return;
default:
break;
}
}
async sendActions(interaction: ChatInputCommandInteraction<CacheType>) {}
}

View File

@ -60,7 +60,11 @@ export default class DiscordService {
const modal = getQuoteModal();
if (interaction.isButton() || interaction.isChatInputCommand()) {
await interaction.showModal(modal);
try {
await interaction.showModal(modal);
} catch (e) {
console.error(e);
}
}
}
@ -102,10 +106,14 @@ export default class DiscordService {
await channel.send(content);
if (interaction.isChatInputCommand() || interaction.isModalSubmit()) {
await interaction.reply({
content: "Completed!",
ephemeral: true,
});
try {
await interaction.reply({
content: "Completed!",
ephemeral: true,
});
} catch (e) {
console.error(e);
}
}
return;