Fixed slash cmd registration bug

This was caused by already registered commands of a different type than 'chatInput'.
This commit is contained in:
DJj123dj
2025-05-31 10:24:04 +02:00
parent 0d8dd8cd17
commit 48f0d65fad
+12 -6
View File
@@ -579,8 +579,8 @@ export class ODSlashCommandComparator {
} }
} }
/**Convert a `ODSlashCommandBuilder` to a universal Open Ticket slash command object for comparison. */ /**Convert a `ODSlashCommandBuilder` to a universal Open Ticket slash command object for comparison. */
convertBuilder(builder:ODSlashCommandBuilder,guildId:string|null): ODSlashCommandUniversalCommand { convertBuilder(builder:ODSlashCommandBuilder,guildId:string|null): ODSlashCommandUniversalCommand|null {
if (builder.type != discord.ApplicationCommandType.ChatInput) throw new ODSystemError("ODSlashCommandComparator:convertBuilder() is not supported for other types than 'ChatInput'!") 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 nameLoc = builder.nameLocalizations ?? {}
const descLoc = builder.descriptionLocalizations ?? {} const descLoc = builder.descriptionLocalizations ?? {}
return { return {
@@ -599,8 +599,8 @@ export class ODSlashCommandComparator {
} }
} }
/**Convert a `discord.ApplicationCommand` to a universal Open Ticket slash command object for comparison. */ /**Convert a `discord.ApplicationCommand` to a universal Open Ticket slash command object for comparison. */
convertCommand(cmd:discord.ApplicationCommand): ODSlashCommandUniversalCommand { convertCommand(cmd:discord.ApplicationCommand): ODSlashCommandUniversalCommand|null {
if (cmd.type != discord.ApplicationCommandType.ChatInput) throw new ODSystemError("ODSlashCommandComparator:convertCommand() is not supported for other types than 'ChatInput'!") 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 nameLoc = cmd.nameLocalizations ?? {}
const descLoc = cmd.descriptionLocalizations ?? {} const descLoc = cmd.descriptionLocalizations ?? {}
return { return {
@@ -812,6 +812,10 @@ export class ODSlashCommandManager extends ODManager<ODSlashCommand> {
//command is registered (and may need to be updated) //command is registered (and may need to be updated)
const universalBuilder = this.comparator.convertBuilder(instance.builder,instance.guildId) const universalBuilder = this.comparator.convertBuilder(instance.builder,instance.guildId)
const universalCmd = this.comparator.convertCommand(cmd) 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 didChange = !this.comparator.compare(universalBuilder,universalCmd)
const requiresUpdate = didChange || (instance.requiresUpdate ? instance.requiresUpdate(universalCmd) : false) const requiresUpdate = didChange || (instance.requiresUpdate ? instance.requiresUpdate(universalCmd) : false)
registered.push({instance,cmd:universalCmd,requiresUpdate}) registered.push({instance,cmd:universalCmd,requiresUpdate})
@@ -821,8 +825,10 @@ export class ODSlashCommandManager extends ODManager<ODSlashCommand> {
}) })
cmds.forEach((cmd) => { cmds.forEach((cmd) => {
//command does not exist in the manager //command does not exist in the manager (only append to unused when type == 'chatinput')
unused.push({instance:null,cmd:this.comparator.convertCommand(cmd),requiresUpdate:false}) const universalCmd = this.comparator.convertCommand(cmd)
if (!universalCmd) return
unused.push({instance:null,cmd:universalCmd,requiresUpdate:false})
}) })
return {registered,unregistered,unused} return {registered,unregistered,unused}