Building slash commands differently

Hi, i had a discord bot on v13 and JS and i did this to implement slash commands
module.exports = {
name: 'updatepic',
description: '[ADMIN]',
permissions: [PermissionsBitField.Flags.Administrator], //i handle this in interactionCreate
category: 'database', //irrelevant, just for help command
usage: 'updatepic [link]', //irrelevant, just for help command
examples: ['updatepic default'], //irrelevant, just for help command
options: [
{
name: 'default',
description: 'Photo hors steram',
type: ApplicationCommandOptionType.String,
required: false
},
{
name: 'live',
description: "Photo lors d'un stream",
type: ApplicationCommandOptionType.String,
required: false
}
],
async runInteraction(client, interaction) {}
};
module.exports = {
name: 'updatepic',
description: '[ADMIN]',
permissions: [PermissionsBitField.Flags.Administrator], //i handle this in interactionCreate
category: 'database', //irrelevant, just for help command
usage: 'updatepic [link]', //irrelevant, just for help command
examples: ['updatepic default'], //irrelevant, just for help command
options: [
{
name: 'default',
description: 'Photo hors steram',
type: ApplicationCommandOptionType.String,
required: false
},
{
name: 'live',
description: "Photo lors d'un stream",
type: ApplicationCommandOptionType.String,
required: false
}
],
async runInteraction(client, interaction) {}
};
But i'm trying to do recreate this with TS and i don't seem to be able to do it this way, Also : How should i manage to get this architecture with sub commands ? I find this way easier to read so i'd like to keep it that way if possible
12 Replies
d.js toolkit
d.js toolkit11mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
monbrey
monbrey11mo ago
I mean if you dont want to use the discord.js way Im not sure its up to us to support it. Why doesnt this work?
Adan_ea
Adan_ea11mo ago
It's not that it doesn't work, i just find this heavy and not really easy to read:
.setName('event')
.setDescription('Créer un évènement')
.addStringOption(option =>
option.setName('titre').setDescription("Titre de l'évènement").setRequired(true)
)
.addStringOption(option =>
option
.setName('dateheure')
.setDescription("Date et heure de l'évènement (AAAA-MM-JJ HH:mm)")
.setRequired(true)
)
.addStringOption(option =>
option
.setName('description')
.setDescription("Description de l'évènement")
.setRequired(false)
)
.addStringOption(option =>
option
.setName('imageurl')
.setDescription("URL de l'image (png|jpg|jpeg|gif|webp)")
.setRequired(false)
)
.addNumberOption(option =>
option
.setName('maxparticipants')
.setDescription("Nombre de participants max, les autres seront en file d'attente")
.setRequired(false)
)
.addStringOption(option =>
option.setName('duree').setDescription("Durée de l'évènement").setRequired(false)
),
category: 'events',
permissions: [PermissionsBitField.Flags.ManageEvents],
usage: `event [titre][description][dateheure]<durée><maxparticipants><imageURL>
.setName('event')
.setDescription('Créer un évènement')
.addStringOption(option =>
option.setName('titre').setDescription("Titre de l'évènement").setRequired(true)
)
.addStringOption(option =>
option
.setName('dateheure')
.setDescription("Date et heure de l'évènement (AAAA-MM-JJ HH:mm)")
.setRequired(true)
)
.addStringOption(option =>
option
.setName('description')
.setDescription("Description de l'évènement")
.setRequired(false)
)
.addStringOption(option =>
option
.setName('imageurl')
.setDescription("URL de l'image (png|jpg|jpeg|gif|webp)")
.setRequired(false)
)
.addNumberOption(option =>
option
.setName('maxparticipants')
.setDescription("Nombre de participants max, les autres seront en file d'attente")
.setRequired(false)
)
.addStringOption(option =>
option.setName('duree').setDescription("Durée de l'évènement").setRequired(false)
),
category: 'events',
permissions: [PermissionsBitField.Flags.ManageEvents],
usage: `event [titre][description][dateheure]<durée><maxparticipants><imageURL>
That's how i'm currently "supposed" to do with discord.js 14 (that's how it's done on the doc) But i liked how it was done in v13
monbrey
monbrey11mo ago
thats using builders but you dont have to
Adan_ea
Adan_ea11mo ago
I can just do the first one and use it that way ? But how about the sub commands then ? How can i include them ?
monbrey
monbrey11mo ago
you can use raw objects as long as they match the format Theyre just option types
Adan_ea
Adan_ea11mo ago
Omg i'm gonna try that out, it would be game changer
monbrey
monbrey11mo ago
options: [{
name: 'sub1',
type: ApplicationCommandOptionType.Subcommand,
options: [{
name: 'suboption1',
...
]}
]}
options: [{
name: 'sub1',
type: ApplicationCommandOptionType.Subcommand,
options: [{
name: 'suboption1',
...
]}
]}
Adan_ea
Adan_ea11mo ago
Thanks a lot, i'm gonna try it and i'll come back to you !
Adan_ea
Adan_ea11mo ago
Other question not directly related to the subjet, So the previous bot i used had it's own commands but i cant delete them, any idea ? I'm trying to do this :
export const deleteCMD = (clientId: string) => {
const rest = new REST({ version: '9' }).setToken(process.env.DISCORD_TOKEN!);

rest.put(Routes.applicationCommands(clientId), { body: [] })
.then(() => Logger.info(`Successfully deleted all application commands.`))
.catch(console.error);
};
export const deleteCMD = (clientId: string) => {
const rest = new REST({ version: '9' }).setToken(process.env.DISCORD_TOKEN!);

rest.put(Routes.applicationCommands(clientId), { body: [] })
.then(() => Logger.info(`Successfully deleted all application commands.`))
.catch(console.error);
};
But it still has the previous commands: EDIT: nvm i'm deleteing them all one by one with the API it seems to work !
d.js docs
d.js docs11mo ago
If you have duplicate commands on your server, you registered both global and guild commands. You can remove the duplicates by resetting either the global or guild commands - Resetting global commands: rest.put(Routes.applicationCommands(clientId), { body: [] }) - Resetting guild commands: rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: [] })
Adan_ea
Adan_ea11mo ago
yeah my bad sorry, but hey at least i fixed it ! And thanks for the help the issue is resolved