Could not pass a new instance of slash command builder to registry.registerApplicationCommands

I have found out that subcommand and subcommand group type is omitted when passing a newly instance of builder. When using the callback method it's not omitted 🤔 reproduction sample: https://github.com/yuanstuffs/registry-reproduction-sample
13 Replies
yuansheng
yuanshengOP•4w ago
No description
yuansheng
yuanshengOP•4w ago
import { ApplyOptions } from '@sapphire/decorators';
import { Command, type ApplicationCommandRegistry } from '@sapphire/framework';
import { ApplicationIntegrationType, InteractionContextType, SlashCommandBuilder } from 'discord.js';

@ApplyOptions<Command.Options>({
description: 'A command that will fail to register'
})
export class UserCommand extends Command {
public override chatInputRun() {}

public override registerApplicationCommands(registry: ApplicationCommandRegistry) {
const builder = new SlashCommandBuilder()
.setName(this.name)
.setDescription(this.description)
.setContexts(InteractionContextType.Guild)
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall)
.addSubcommandGroup((builder) =>
builder
.setName('g')
.setDescription('group')
.addSubcommand((builder) => builder.setName('sub').setDescription('sub'))
);

registry.registerChatInputCommand(builder);
}
}
import { ApplyOptions } from '@sapphire/decorators';
import { Command, type ApplicationCommandRegistry } from '@sapphire/framework';
import { ApplicationIntegrationType, InteractionContextType, SlashCommandBuilder } from 'discord.js';

@ApplyOptions<Command.Options>({
description: 'A command that will fail to register'
})
export class UserCommand extends Command {
public override chatInputRun() {}

public override registerApplicationCommands(registry: ApplicationCommandRegistry) {
const builder = new SlashCommandBuilder()
.setName(this.name)
.setDescription(this.description)
.setContexts(InteractionContextType.Guild)
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall)
.addSubcommandGroup((builder) =>
builder
.setName('g')
.setDescription('group')
.addSubcommand((builder) => builder.setName('sub').setDescription('sub'))
);

registry.registerChatInputCommand(builder);
}
}
doing builder.toJSON():
{
options: [
{
type: 2,
name: 'g',
name_localizations: undefined,
description: 'group',
description_localizations: undefined,
options: [Array]
}
],
name: 'fail-group',
name_localizations: undefined,
description: 'A command that will fail to register',
description_localizations: undefined,
contexts: [ 0 ],
default_permission: undefined,
default_member_permissions: undefined,
dm_permission: undefined,
integration_types: [ 0 ],
nsfw: undefined,
type: 1
}
{
options: [
{
type: 2,
name: 'g',
name_localizations: undefined,
description: 'group',
description_localizations: undefined,
options: [Array]
}
],
name: 'fail-group',
name_localizations: undefined,
description: 'A command that will fail to register',
description_localizations: undefined,
contexts: [ 0 ],
default_permission: undefined,
default_member_permissions: undefined,
dm_permission: undefined,
integration_types: [ 0 ],
nsfw: undefined,
type: 1
}
yuansheng
yuanshengOP•4w ago
Same as registering subcommands.
{
options: [
{
type: 1,
name: 'failure',
name_localizations: undefined,
description: 'Failure',
description_localizations: undefined,
options: []
}
],
name: 'fail',
name_localizations: undefined,
description: 'This will fail to register.',
description_localizations: undefined,
contexts: [ 0 ],
default_permission: undefined,
default_member_permissions: undefined,
dm_permission: undefined,
integration_types: [ 0 ],
nsfw: undefined,
type: 1
}
{
options: [
{
type: 1,
name: 'failure',
name_localizations: undefined,
description: 'Failure',
description_localizations: undefined,
options: []
}
],
name: 'fail',
name_localizations: undefined,
description: 'This will fail to register.',
description_localizations: undefined,
contexts: [ 0 ],
default_permission: undefined,
default_member_permissions: undefined,
dm_permission: undefined,
integration_types: [ 0 ],
nsfw: undefined,
type: 1
}
No description
yuansheng
yuanshengOP•3w ago
subcommands and sub groups are being omitted .
Favna
Favna•3w ago
I am running a bot with subcommands just fine so i have no idea what is going wrong here.
Favna
Favna•3w ago
yuansheng
yuanshengOP•3w ago
Using the callback method have no issues, how about try making a new instance of the slash command builder class with subcommands and pass it to the register chat input command function
Favna
Favna•3w ago
oh that's what you meant. hm yeah I think I reported before to @vladdy that passing an instance doesnt work properly
Azrael⛧⸸
Azrael⛧⸸•2w ago
Have you figured this out with an instance? I found the problem in the code itself
Azrael⛧⸸
Azrael⛧⸸•2w ago
the problem lies in @sapphire/framework/lib/utils/application-commands/normalizeInputs. The builder passed is never recognized as a builder so it just goes thru trest of the code
No description
Azrael⛧⸸
Azrael⛧⸸•2w ago
I found the problem lool. I was using SlashCommandBuilder from Discord.js where the SlashCommandBuilder instance check happens in @discordjs/builders So in technicality builder from discord.js package and builder from builders package is not the same For now, a fix is to import builders that are related to commands from @discordjs/builders instead of discord.js
Favna
Favna•2w ago
Can you check your lockfile see if you have 2 versions of builders? Because discordjs re-exports /builders and they should be identical. This is a bug I've known about but never figured out why.
Azrael⛧⸸
Azrael⛧⸸•2w ago
they are two versions of them, but they are identical versions Idk why Javascript treats an import from djs differently from builders

Did you find this page helpful?