Slash Commands
We now have slash commands! This guide will take you through building them!
Invite Scopes
Before making any slash command, make sure your bot is invited to servers via a invite link with the bot
and applications.commands
scopes. If it wasn't invited using these scopes, you must kick it from the server and re-invite with the proper scopes; in order for slash commands to work.
How Do I Invite My Bot With The Proper Scopes? 1. Go to the Discord Developer Portal
2. Select a application.
3. Go to the "OAuth2" section.

4. Select the needed scopes and copy the invite. After that, if needed, kick the bot. Then, re-invite it with the new invite URL.

Creating Slash Commands
First need to define the slash command's info through bot.createSlashCommandData()
.
bot.createSlashCommandData({
name: "test",
description: "A simple slash command.",
options: [
{
name: "message",
description: "What should I say?",
type: "STRING",
required: true
},
{
name: "target", // The name of the slash command option.
description: "The person to mention.", // The description of the option.
type: "USER", // The option type.
required: false // Whether or not the argumemt is required.
}
]
})
// The 'options' fields are optional.
Slash Command Option Types
Option types change what the user is suppose to input. Below is a list of all types you can input:
STRING
NUMBER
USER
ROLE
CHANNEL
BOOLEAN
Now, we have to add it to a server or globally to every server.
//for global
bot.command({
type: "readyCommand",
code: `$createSlashCommand[global;test]` // last field is the name of the slash command.
})
//for server specific
bot.command({
type: "readyCommand",
code: `$createSlashCommand[844681827015720991;test]` // first field is the ID of the guild to add the slash command to.
})
You've created a slash command. Now all you have to do is make the bot's reply! Check out the example below.
bot.addEvent("onInteraction") // Enables both slash commands and button interactions.
bot.command({
type: "slashCommand",
name: "test", // the name of our slash command
code: `$username said $slashOption[message]`
})
You should restart your bot after making these changes!
Last updated
Was this helpful?