Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log the arguments of the command on error #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lang/logs.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
"button": "An error occurred while processing a button interaction.",
"commandNotFound": "[{INTERACTION_ID}] A command with the name '{COMMAND_NAME}' could not be found.",
"autocompleteNotFound": "[{INTERACTION_ID}] An autocomplete method for the '{COMMAND_NAME}' command could not be found.",
"commandGuild": "[{INTERACTION_ID}] An error occurred while executing the '{COMMAND_NAME}' command for user '{USER_TAG}' ({USER_ID}) in channel '{CHANNEL_NAME}' ({CHANNEL_ID}) in guild '{GUILD_NAME}' ({GUILD_ID}).",
"autocompleteGuild": "[{INTERACTION_ID}] An error occurred while autocompleting the '{OPTION_NAME}' option for the '{COMMAND_NAME}' command for user '{USER_TAG}' ({USER_ID}) in channel '{CHANNEL_NAME}' ({CHANNEL_ID}) in guild '{GUILD_NAME}' ({GUILD_ID}).",
"commandGuild": "[{INTERACTION_ID}] An error occurred while executing the '{COMMAND_NAME}' command for user '{USER_TAG}' ({USER_ID}) in channel '{CHANNEL_NAME}' ({CHANNEL_ID}) in guild '{GUILD_NAME}' ({GUILD_ID}). Arguments: {ARGUMENTS}.",
"autocompleteGuild": "[{INTERACTION_ID}] An error occurred while autocompleting the '{OPTION_NAME}' option for the '{COMMAND_NAME}' command for user '{USER_TAG}' ({USER_ID}) in channel '{CHANNEL_NAME}' ({CHANNEL_ID}) in guild '{GUILD_NAME}' ({GUILD_ID}). Arguments: {ARGUMENTS}.",
"commandOther": "[{INTERACTION_ID}] An error occurred while executing the '{COMMAND_NAME}' command for user '{USER_TAG}' ({USER_ID}).",
"autocompleteOther": "[{INTERACTION_ID}] An error occurred while autocompleting the '{OPTION_NAME}' option for the '{COMMAND_NAME}' command for user '{USER_TAG}' ({USER_ID}).",
"apiRequest": "An error occurred while processing a '{HTTP_METHOD}' request to '{URL}'.",
Expand Down
15 changes: 10 additions & 5 deletions src/events/command-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ export class CommandHandler implements EventHandler {
Config.rateLimiting.commands.interval * 1000
);

constructor(
public commands: Command[],
private eventDataService: EventDataService
) {}
constructor(public commands: Command[], private eventDataService: EventDataService) {}

public async process(intr: CommandInteraction | AutocompleteInteraction): Promise<void> {
// Don't respond to self, or other bots
Expand Down Expand Up @@ -144,6 +141,12 @@ export class CommandHandler implements EventHandler {
} catch (error) {
await this.sendError(intr, data);

let args = intr.options.data
.map(option => {
return `${option.name}: ${option.value}`;
Copy link
Owner

@KevinNovak KevinNovak Jun 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just trying to think, is option.value ever something really long? Like what about an attachment?

})
.join(', ');

// Log command error
Logger.error(
intr.channel instanceof TextChannel ||
Expand All @@ -158,11 +161,13 @@ export class CommandHandler implements EventHandler {
.replaceAll('{CHANNEL_ID}', intr.channel.id)
.replaceAll('{GUILD_NAME}', intr.guild?.name)
.replaceAll('{GUILD_ID}', intr.guild?.id)
.replaceAll('{ARGUMENTS}', args)
: Logs.error.commandOther
.replaceAll('{INTERACTION_ID}', intr.id)
.replaceAll('{COMMAND_NAME}', commandName)
.replaceAll('{USER_TAG}', intr.user.tag)
.replaceAll('{USER_ID}', intr.user.id),
.replaceAll('{USER_ID}', intr.user.id)
.replaceAll('{ARGUMENTS}', args),
error
);
}
Expand Down