Getting started
Last updated
Last updated
Use the package manager to install @mxgnus/slashcommands.js.
npm i @mxgnus/slashcommands.js
const {
GuildSlashCommand,
Slashcommand,
Slash,
} = require('@mxgnus/slashcommands.js');
new Slash(bot /* your discord.js client */); // initialize the slash command
// create a guild slashcommand
new GuildSlashCommand()
.setGuildId('your guild id')
.setName('commandname')
.setDescription('command description')
.register();
// create a global slashcommand
new Slashcommand()
.setName('commandname')
.setDescription('command description')
.register();
// create a guild slashcommand with options
const {
GuildSlashCommand,
Slash,
SlashcommandOption,
} = require('@mxgnus/slashcommands.js');
new Slash(bot /* your discord.js client */); // initialize the slash command
const nameOption = new SlashcommandOption()
.setName('name')
.setDescription('Name')
.setType('STRING')
.setRequired(true);
new GuildSlashCommand()
.setGuildId('your guild id')
.setName('name')
.setDescription('Enter your name')
.addOption(nameOption)
.register();
// create a global slashcommand with options
const {
SlashCommand,
Slash,
SlashcommandOption,
} = require('@mxgnus/slashcommands.js');
const nameOption = new SlashcommandOption()
.setName('name')
.setDescription('Name')
.setType('STRING')
.setRequired(true);
new SlashCommand()
.setName('name')
.setDescription('Enter your name')
.addOption(nameOption)
.register();
// create a guild slashcommand with options and choices
const {
GuildSlashCommand,
Slash,
SlashcommandOption,
SlashCommandOptionChoice,
} = require('@mxgnus/slashcommands.js');
new Slash(bot /* your discord.js client */); // initialize the slash command
const nameChoice1 = new SlashCommandOptionChoice()
.setName('name1')
.setValue('Name 1');
const nameChoice2 = new SlashCommandOptionChoice()
.setName('name2')
.setValue('Name 2');
const nameOption = new SlashcommandOption()
.setName('name')
.setDescription('Name')
.setType('STRING')
.setRequired(true)
.setChoices([nameChoice1, nameChoice2]);
new GuildSlashCommand()
.setGuildId('your guild id')
.setName('name')
.setDescription('Enter your name')
.addOption(nameOption)
.register();
// create a global slashcommand with options and choices
const {
SlashCommand,
Slash,
SlashcommandOption,
SlashCommandOptionChoice,
} = require('@mxgnus/slashcommands.js');
const nameChoice1 = new SlashCommandOptionChoice()
.setName('name1')
.setValue('Name 1');
const nameChoice2 = new SlashCommandOptionChoice()
.setName('name2')
.setValue('Name 2');
const nameOption = new SlashcommandOption()
.setName('name')
.setDescription('Name')
.setType('STRING')
.setRequired(true)
.setChoices([nameChoice1, nameChoice2]);
new SlashCommand()
.setName('name')
.setDescription('Enter your name')
.addOption(nameOption)
.register();
const {
fetchGuildSlashcommands,
fetchSlashcommands,
Slash,
} = require('@mxgnus/slashcommands.js');
new Slash(bot /* your discord.js client */); // initialize the slash command
// fetch all guild slashcommands
const guildSlashCommands = await fetchGuildSlashcommands();
// fetch all global slashcommands
const slashCommands = await fetchSlashcommands();
const {
deleteGuildSlashcommand,
deleteSlashcommand,
Slash,
} = require('@mxgnus/slashcommands.js');
new Slash(bot /* your discord.js client */); // initialize the slash command
// delete a guild slashcommand by name
deleteGuildSlashcommand({
guildId: 'your guild id',
name: 'command name',
});
// delete a guild slashcommand by id
deleteGuildSlashcommand({
guildId: 'your guild id',
id: 'command id',
});
// delete a global slashcommand by name
deleteSlashcommand({
name: 'command name',
});
// delete a global slashcommand by id
deleteSlashcommand({
id: 'command id',
});
const {
deleteAllGuildSlashcommands,
deleteAllSlashcommands,
Slash,
} = require('@mxgnus/slashcommands.js');
new Slash(bot /* your discord.js client */); // initialize the slash command
// Delete all guild slashcommands
deleteAllGuildSlashcommands({
guildId: 'your guild id'
});
// Delete all global slashcommands
deleteAllSlashcommands()
bot.on('interactionCreate', async (interaction) => {
if (interaction.isCommand()) {
if (interaction.commandName === 'test') {
interaction.reply('test');
}
}
});
application.commands
permission:https://discord.com/api/oauth2/authorize?client_id=YOUR_CLIENT_ID&permissions=0scope=applications.commands%20bot