From 48f0d65faded5f0025695a764c2fccf890f64fa1 Mon Sep 17 00:00:00 2001 From: DJj123dj <80536295+DJj123dj@users.noreply.github.com> Date: Sat, 31 May 2025 10:24:04 +0200 Subject: [PATCH] Fixed slash cmd registration bug This was caused by already registered commands of a different type than 'chatInput'. --- src/core/api/modules/client.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/core/api/modules/client.ts b/src/core/api/modules/client.ts index d2e2868..60b0c44 100644 --- a/src/core/api/modules/client.ts +++ b/src/core/api/modules/client.ts @@ -579,8 +579,8 @@ export class ODSlashCommandComparator { } } /**Convert a `ODSlashCommandBuilder` to a universal Open Ticket slash command object for comparison. */ - convertBuilder(builder:ODSlashCommandBuilder,guildId:string|null): ODSlashCommandUniversalCommand { - if (builder.type != discord.ApplicationCommandType.ChatInput) throw new ODSystemError("ODSlashCommandComparator:convertBuilder() is not supported for other types than 'ChatInput'!") + convertBuilder(builder:ODSlashCommandBuilder,guildId:string|null): ODSlashCommandUniversalCommand|null { + if (builder.type != discord.ApplicationCommandType.ChatInput) return null //throw new ODSystemError("ODSlashCommandComparator:convertBuilder() is not supported for other types than 'ChatInput'!") const nameLoc = builder.nameLocalizations ?? {} const descLoc = builder.descriptionLocalizations ?? {} return { @@ -599,8 +599,8 @@ export class ODSlashCommandComparator { } } /**Convert a `discord.ApplicationCommand` to a universal Open Ticket slash command object for comparison. */ - convertCommand(cmd:discord.ApplicationCommand): ODSlashCommandUniversalCommand { - if (cmd.type != discord.ApplicationCommandType.ChatInput) throw new ODSystemError("ODSlashCommandComparator:convertCommand() is not supported for other types than 'ChatInput'!") + convertCommand(cmd:discord.ApplicationCommand): ODSlashCommandUniversalCommand|null { + if (cmd.type != discord.ApplicationCommandType.ChatInput) return null //throw new ODSystemError("ODSlashCommandComparator:convertCommand() is not supported for other types than 'ChatInput'!") const nameLoc = cmd.nameLocalizations ?? {} const descLoc = cmd.descriptionLocalizations ?? {} return { @@ -812,6 +812,10 @@ export class ODSlashCommandManager extends ODManager { //command is registered (and may need to be updated) const universalBuilder = this.comparator.convertBuilder(instance.builder,instance.guildId) const universalCmd = this.comparator.convertCommand(cmd) + + //command is not of the type 'chatinput' + if (!universalBuilder || !universalCmd) return + const didChange = !this.comparator.compare(universalBuilder,universalCmd) const requiresUpdate = didChange || (instance.requiresUpdate ? instance.requiresUpdate(universalCmd) : false) registered.push({instance,cmd:universalCmd,requiresUpdate}) @@ -821,8 +825,10 @@ export class ODSlashCommandManager extends ODManager { }) cmds.forEach((cmd) => { - //command does not exist in the manager - unused.push({instance:null,cmd:this.comparator.convertCommand(cmd),requiresUpdate:false}) + //command does not exist in the manager (only append to unused when type == 'chatinput') + const universalCmd = this.comparator.convertCommand(cmd) + if (!universalCmd) return + unused.push({instance:null,cmd:universalCmd,requiresUpdate:false}) }) return {registered,unregistered,unused}