Variable parameter type based on the previous variable

I want to add a 'parametric' set subcommand to one of my commands For that command the values can be user, role or a string. Can I somehow change the option type (for example use addRoleOption instead of addStringOption) based on the value of the type option?
.addSubcommand((subcommand) => {
return subcommand
.setName('set')
.setDescription(i18next.t(`${this.translationPath}.subcommandDescription.settings`))
.addStringOption((option) => {
return option
.setName('name')
.setDescription(i18next.t(`${this.translationPath}.optionDescription.name`))
.setRequired(true)
.setAutocomplete(true);
})
.addStringOption((option) => {
return option
.setName('type')
.setDescription(i18next.t(`${this.translationPath}.optionDescription.type`))
.setRequired(true)
.setChoices(
{
name: 'name',
value: 'Name'
},
{
name: 'user',
value: 'User'
},
{
name: 'role',
value: 'Role'
}
);
})
.addStringOption((option) => {
return option
.setName('value')
.setDescription(i18next.t(`${this.translationPath}.optionDescription.value`))
.setRequired(true);
});
})
.addSubcommand((subcommand) => {
return subcommand
.setName('set')
.setDescription(i18next.t(`${this.translationPath}.subcommandDescription.settings`))
.addStringOption((option) => {
return option
.setName('name')
.setDescription(i18next.t(`${this.translationPath}.optionDescription.name`))
.setRequired(true)
.setAutocomplete(true);
})
.addStringOption((option) => {
return option
.setName('type')
.setDescription(i18next.t(`${this.translationPath}.optionDescription.type`))
.setRequired(true)
.setChoices(
{
name: 'name',
value: 'Name'
},
{
name: 'user',
value: 'User'
},
{
name: 'role',
value: 'Role'
}
);
})
.addStringOption((option) => {
return option
.setName('value')
.setDescription(i18next.t(`${this.translationPath}.optionDescription.value`))
.setRequired(true);
});
})
Solution:
I think this is possible if you use Auto complete If I'm correct, Autocomplete interaction should be able to give you values of previously filled parameters, which you can use to dynamically present values...
Jump to solution
4 Replies
Solution
MRDGH2821
MRDGH28218mo ago
I think this is possible if you use Auto complete If I'm correct, Autocomplete interaction should be able to give you values of previously filled parameters, which you can use to dynamically present values
KaydaFox
KaydaFox8mo ago
Technically that should work if autocomlete allows that, I forget, but then you'd have to be using just IDs and manually mapping over the servers users and roles
Favna
Favna8mo ago
Yeh you can do this with autocomplete but the code won't be pretty. It's still the best way to do it though, at least, much better than message commands or such. You can use focusedOption to get the arg being parsed.
Feralheart
FeralheartOP8mo ago
Thank you all for the replies
Want results from more Discord servers?
Add your server