Skip to content

Commit 4057438

Browse files
authored
Update error helper (#39)
1 parent 2c740a7 commit 4057438

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

src/commands/about/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export default {
5656
.setDescription('Displays information about My App'),
5757
async execute({ interaction, app }: AppCommandOptions) {
5858
try {
59+
await interaction.deferReply();
5960
const embed = generateAboutEmbed(app);
6061
await interaction.reply({ embeds: [embed] });
6162
} catch (error) {

src/commands/commands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SlashCommandBuilder } from '@discordjs/builders';
2-
import { Client, CommandInteraction } from 'discord.js';
2+
import { ChatInputCommandInteraction, Client } from 'discord.js';
33
import fs from 'fs';
44
import path from 'path';
55

@@ -9,7 +9,7 @@ export type AppCommand = {
99
execute: (data: AppCommandOptions) => Promise<void>;
1010
};
1111
export type AppCommandOptions = {
12-
interaction: CommandInteraction;
12+
interaction: ChatInputCommandInteraction;
1313
app: Client;
1414
appCommands?: AppCommand[];
1515
};

src/commands/help/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export default {
3939
data: new SlashCommandBuilder().setName('help').setDescription('Directory hub of commands'),
4040
async execute({ interaction, appCommands }: AppCommandOptions) {
4141
try {
42+
await interaction.deferReply();
4243
const embed = generateHelpEmbed(appCommands);
4344
await interaction.reply({ embeds: [embed] });
4445
} catch (error) {

src/commands/invite/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default {
1717
.setDescription('Generates an invite link for My App'),
1818
async execute({ interaction }: AppCommandOptions) {
1919
try {
20+
await interaction.deferReply();
2021
const embed = generateInviteEmbed();
2122
await interaction.reply({ embeds: [embed] });
2223
} catch (error) {

src/utils/helpers.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {
33
APIEmbed,
44
ButtonInteraction,
55
Channel,
6+
ChatInputCommandInteraction,
67
Client,
7-
CommandInteraction,
88
Guild,
99
GuildChannel,
1010
inlineCode,
@@ -65,9 +65,15 @@ export const serverNotificationEmbed = async ({
6565
export const sendErrorLog = async ({
6666
error,
6767
interaction,
68+
option,
69+
subCommand,
70+
customTitle,
6871
}: {
6972
error: any;
70-
interaction?: CommandInteraction;
73+
interaction?: ChatInputCommandInteraction | AnySelectMenuInteraction | ButtonInteraction;
74+
option?: string | null;
75+
subCommand?: string;
76+
customTitle?: string;
7177
}) => {
7278
console.error(error);
7379
const errorID = uuid();
@@ -78,14 +84,22 @@ export const sendErrorLog = async ({
7884
}\nError ID: ${inlineCode(errorID)}`,
7985
color: getEmbedColor('#FF0000'),
8086
};
81-
await interaction.editReply({ embeds: [errorEmbed] });
87+
await interaction.editReply({ embeds: [errorEmbed], components: [] });
8288
}
8389
if (ERROR_NOTIFICATION_WEBHOOK_URL && !isEmpty(ERROR_NOTIFICATION_WEBHOOK_URL)) {
8490
const interactionChannel = interaction?.channel as GuildChannel | undefined;
8591
const notificationEmbed: APIEmbed = {
86-
title: interaction ? `Error | ${capitalize(interaction.commandName)} Command` : 'Error',
92+
title: customTitle
93+
? `Error | ${customTitle}`
94+
: interaction
95+
? `Error | ${interaction.isCommand() ? capitalize(interaction.commandName) : ''}${
96+
subCommand ? ` ${capitalize(subCommand)}` : ''
97+
} Command`
98+
: 'Error',
8799
color: getEmbedColor('#FF0000'),
88-
description: `uuid: ${errorID}\nError: ${error.message ? error.message : 'Unexpected Error'}`,
100+
description: `uuid: ${errorID}\nError: ${
101+
error.message ? error.message : 'Unexpected Error'
102+
}\n${option ? `Option: ${option}` : ''}`,
89103
fields: interaction
90104
? [
91105
{

0 commit comments

Comments
 (0)