Skip to content

Commit 2dfe578

Browse files
Move to always deferring
1 parent 014f3d0 commit 2dfe578

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/commands/docs/djs.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ const command: Command = {
3838
if (!resultEmbed) {
3939
const timeStampDate = new Date(notFoundEmbed.timestamp);
4040
const embedObj = { ...notFoundEmbed, timestamp: timeStampDate };
41-
return interaction.reply({ embeds: [embedObj] }).catch(console.error);
41+
interaction.editReply({ embeds: [embedObj] }).catch(console.error);
42+
return
4243
}
4344

4445
const timeStampDate = new Date(resultEmbed.timestamp);
@@ -47,7 +48,7 @@ const command: Command = {
4748
// The final fields should be the View Source button
4849
embedObj.fields = [embedObj.fields?.at(-1)]
4950
}
50-
interaction.reply({ embeds: [embedObj] }).catch(console.error);
51+
interaction.editReply({ embeds: [embedObj] }).catch(console.error);
5152
return;
5253
},
5354
};

src/handlers/CommandHandler.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ export async function commandHandler(
88
interaction: Interaction
99
) {
1010
if (interaction.isCommand()) {
11+
await interaction.deferReply();
1112
const command = context.commands.get(interaction.commandName);
12-
if (!command) return interaction.reply(`Command not found`);
13+
if (!command) return interaction.editReply(`Command not found`);
1314

1415
if (commandPermissionCheck(interaction, command)) return;
1516
if (commandCooldownCheck(interaction, command, context)) return;
@@ -18,9 +19,7 @@ export async function commandHandler(
1819
} catch (e) {
1920
console.error(e);
2021
const errorMessage = "An error has occurred";
21-
interaction.replied
22-
? interaction.reply(errorMessage).catch(console.error)
23-
: interaction.editReply(errorMessage).catch(console.error);
22+
interaction.editReply(errorMessage).catch(console.error);
2423
}
2524
}
2625
}
@@ -65,7 +64,9 @@ function commandPermissionCheck(
6564
if (channel.type === "DM" || !channel) {
6665
if (command.guildOnly) {
6766
interaction
68-
.reply(`This is a guild exclusive command, not to be executed in a dm`)
67+
.editReply(
68+
`This is a guild exclusive command, not to be executed in a dm`
69+
)
6970
.catch(console.error);
7071
// For guild only commands that were executed in a dm, cancel the command
7172
return true;
@@ -81,7 +82,7 @@ function commandPermissionCheck(
8182
.missing(botPermissions);
8283
if (missingPermissions.length > 0) {
8384
interaction
84-
.reply(
85+
.editReply(
8586
`In order to run this command, I need the following permissions: ${missingPermissions
8687
.map((perm) => `\`${perm}\``)
8788
.join(", ")}`
@@ -98,7 +99,7 @@ function commandPermissionCheck(
9899
.missing(authorPermissions);
99100
if (missingPermissions.length > 0) {
100101
interaction
101-
.reply(
102+
.editReply(
102103
`In order to run this command, you need: ${missingPermissions
103104
.map((perm) => `\`${perm}\``)
104105
.join(", ")}`
@@ -125,7 +126,7 @@ function commandCooldownCheck(
125126
return false;
126127
}
127128
interaction
128-
.reply(
129+
.editReply(
129130
`Please wait ${Formatters.time(
130131
Date.now() + existingCooldown,
131132
"R"

0 commit comments

Comments
 (0)