Validation error in `SlashCommandBuilder.addSubcommand`

I'm registering a command with a single sub command as such (pardon the poor indentation, copying to Discord is... annoying)
registry.registerChatInputCommand(
(builder) =>
builder
.setName('leaderboards') //
.setDescription('Manage leaderboards.')
.setDMPermission(false)
.setDefaultMemberPermissions(PermissionFlagsBits.ManageChannels)
.addSubcommand(
new SlashCommandSubcommandBuilder() //
.setName('deploy')
.setDescription('Deploys a leaderboard of a given metric in this channel.')
.addStringOption(
new SlashCommandStringOption() //
.setName('metric')
.setDescription("The leaderboard's tracked metric type.")
.setRequired(true)
.setChoices<APIApplicationCommandOptionChoice<LeaderboardType>>([
{
name: 'Appointments Set',
value: LeaderboardType.AppointmentsSet
},
{
name: 'Showed Up To Appointments',
value: LeaderboardType.ShowedUpToAppointments
},
{
name: 'Sequence Subscriptions',
value: LeaderboardType.SequenceSubscriptions
},
{
name: 'Completed Calls',
value: LeaderboardType.CompletedCalls
}
])
)
)
);
registry.registerChatInputCommand(
(builder) =>
builder
.setName('leaderboards') //
.setDescription('Manage leaderboards.')
.setDMPermission(false)
.setDefaultMemberPermissions(PermissionFlagsBits.ManageChannels)
.addSubcommand(
new SlashCommandSubcommandBuilder() //
.setName('deploy')
.setDescription('Deploys a leaderboard of a given metric in this channel.')
.addStringOption(
new SlashCommandStringOption() //
.setName('metric')
.setDescription("The leaderboard's tracked metric type.")
.setRequired(true)
.setChoices<APIApplicationCommandOptionChoice<LeaderboardType>>([
{
name: 'Appointments Set',
value: LeaderboardType.AppointmentsSet
},
{
name: 'Showed Up To Appointments',
value: LeaderboardType.ShowedUpToAppointments
},
{
name: 'Sequence Subscriptions',
value: LeaderboardType.SequenceSubscriptions
},
{
name: 'Completed Calls',
value: LeaderboardType.CompletedCalls
}
])
)
)
);
It's throwing the following error attached in the screenshot. I have no TS errors and I'm not quite sure what's wrong here.
No description
Solution:
instead of importing the functions just pass the builder callback: ```ts registry.registerChatInputCommand((builder) => builder .setName('leaderboards') //...
Jump to solution
14 Replies
Solution
Favna
Favna4mo ago
instead of importing the functions just pass the builder callback:
registry.registerChatInputCommand((builder) =>
builder
.setName('leaderboards') //
.setDescription('Manage leaderboards.')
.setDMPermission(false)
.setDefaultMemberPermissions(PermissionFlagsBits.ManageChannels)
.addSubcommand((builder) =>
builder
.setName('deploy')
.setDescription('Deploys a leaderboard of a given metric in this channel.')
.addStringOption((builder) =>
builder
.setName('metric')
.setDescription("The leaderboard's tracked metric type.")
.setRequired(true)
.setChoices<APIApplicationCommandOptionChoice<LeaderboardType>>([
{
name: 'Appointments Set',
value: LeaderboardType.AppointmentsSet
},
{
name: 'Showed Up To Appointments',
value: LeaderboardType.ShowedUpToAppointments
},
{
name: 'Sequence Subscriptions',
value: LeaderboardType.SequenceSubscriptions
},
{
name: 'Completed Calls',
value: LeaderboardType.CompletedCalls
}
])
)
)
);
registry.registerChatInputCommand((builder) =>
builder
.setName('leaderboards') //
.setDescription('Manage leaderboards.')
.setDMPermission(false)
.setDefaultMemberPermissions(PermissionFlagsBits.ManageChannels)
.addSubcommand((builder) =>
builder
.setName('deploy')
.setDescription('Deploys a leaderboard of a given metric in this channel.')
.addStringOption((builder) =>
builder
.setName('metric')
.setDescription("The leaderboard's tracked metric type.")
.setRequired(true)
.setChoices<APIApplicationCommandOptionChoice<LeaderboardType>>([
{
name: 'Appointments Set',
value: LeaderboardType.AppointmentsSet
},
{
name: 'Showed Up To Appointments',
value: LeaderboardType.ShowedUpToAppointments
},
{
name: 'Sequence Subscriptions',
value: LeaderboardType.SequenceSubscriptions
},
{
name: 'Completed Calls',
value: LeaderboardType.CompletedCalls
}
])
)
)
);
Teixeira
Teixeira4mo ago
Yeah this is it... Why do TS types accept the respective builder instances though? By the way @Answer Overflow isn't working atm
Favna
Favna4mo ago
@vladdy looks like SlashCommandStringOption doesnt get recognised as something that has to be built, and calling .toJSON() gives the TS error
Argument of type 'APIApplicationCommandStringOption' is not assignable to parameter of type 'SlashCommandStringOption | ((builder: SlashCommandStringOption) => SlashCommandStringOption)'.
Type 'APIApplicationCommandStringOptionBase & { autocomplete: true; choices?: [] | undefined; }' is not assignable to type 'SlashCommandStringOption | ((builder: SlashCommandStringOption) => SlashCommandStringOption)'.
Type 'APIApplicationCommandStringOptionBase & { autocomplete: true; choices?: [] | undefined; }' is missing the following properties from type 'SlashCommandStringOption': setMaxLength, setMinLength, toJSON, setRequired, and 10 more.ts(2345)
Argument of type 'APIApplicationCommandStringOption' is not assignable to parameter of type 'SlashCommandStringOption | ((builder: SlashCommandStringOption) => SlashCommandStringOption)'.
Type 'APIApplicationCommandStringOptionBase & { autocomplete: true; choices?: [] | undefined; }' is not assignable to type 'SlashCommandStringOption | ((builder: SlashCommandStringOption) => SlashCommandStringOption)'.
Type 'APIApplicationCommandStringOptionBase & { autocomplete: true; choices?: [] | undefined; }' is missing the following properties from type 'SlashCommandStringOption': setMaxLength, setMinLength, toJSON, setRequired, and 10 more.ts(2345)
@Rhys, @Answer Overflow is giving application did not respond
vladdy
vladdy4mo ago
thats weird, the validators should work
Teixeira
Teixeira4mo ago
/**
* Adds a new subcommand to this command.
*
* @param input - A function that returns a subcommand builder or an already built builder
*/
addSubcommand(input: SlashCommandSubcommandBuilder | ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder)): TypeAfterAddingSubcommands;
/**
* Adds a new subcommand to this command.
*
* @param input - A function that returns a subcommand builder or an already built builder
*/
addSubcommand(input: SlashCommandSubcommandBuilder | ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder)): TypeAfterAddingSubcommands;
TS types say it should accept the instance directly so I assumed I could
vladdy
vladdy4mo ago
yeah bc it should work maybe I did an oopsie?
Favna
Favna4mo ago
either that or DiscordJS did in /builders
vladdy
vladdy4mo ago
aka me
Favna
Favna4mo ago
(to be fair shapeshift doesnt have function validators yet and when I tried to add them I failed hard)
vladdy
vladdy4mo ago
but this is an instanceof check
Favna
Favna4mo ago
oh right it's a class mb
vladdy
vladdy4mo ago
and also ??? it doesnt get transformed anywhere the heck yeah that is strange
Teixeira
Teixeira4mo ago
Full stack trace in case it helps and version info - @sapphire/plugin-subcommands@6.0.3 @sapphire/framework@5.2.1 discord.js@14.15.2
Rhys
Rhys4mo ago
Weird, sorry about that looks like it’s back now
Want results from more Discord servers?
Add your server