nomad-slashcommands
v1.2.2
Published
Easiest way to use discord.js's slash commands
Downloads
9
Readme
Getting Started
Install nomad-slashcommands using npm:
console $ npm install nomad-slashcommands
Import nomad-slashcommands and create a command with response:
const Discord = require("discord.js");
const client = new Discord.Client();
const sc = require("nomad-slashcommands");
const SlashCommands = new sc.SlashCommands(client);
client.on("ready", () => {
SlashCommands.setGuildID("guildID");
// name, description
const pingCommand = new sc.SlashCommand("ping", "Ping command description.");
SlashCommands.addSlashCommand(pingCommand);
pingCommand.events.on("execute", async (command) => {
await SlashCommands.reply(command.interaction, "Pong!");
});
})
client.login("TOKEN");
Example with options:
const Discord = require("discord.js");
const client = new Discord.Client();
const sc = require("nomad-slashcommands");
const SlashCommands = new sc.SlashCommands(client);
client.on("ready", () => {
SlashCommands.setGuildID("guildID");
// name, description
const pingCommand = new sc.SlashCommand("ping", "Ping command description.");
// name, description, required, type
pingCommand.addOption("pong", "option description", false, 3);
// Adding the slash command.
SlashCommands.addSlashCommand(pingCommand);
// Function called on execute:
pingCommand.events.on("execute", async (command) => {
if(command.args.pong){
await SlashCommands.reply(command.interaction, "Pong!");
return;
}
await SlashCommands.reply(command.interaction, "No pong, sorry..");
});
})
client.login("TOKEN");
Values for the command variable (passed through the execute function)
- interaction
Object
: Interaction data from the command. - args
Object
: Arguments passed through (options). - member
GuildMember
: Member variable (member that sent the command). - channel
Channel
: Channel the command was sent in. - guild
Guild
: Guild the command was sent in.
Functions from SlashCommands
- setClient(client): Sets the client variable.
- setGuildID(guildID): guildID doesn't have to be specified. If it is not, the command will be global (will take 1 hour max to update).
- getCommands(): Returns all commands in a list.
- getApp(): Returns the client API application.
- getCommand(interaction): Returns the command name.
- getOptions(interaction): Returns the options given from the interaction.
- getUser(interaction): Returns the
User
object. - getMember(interaction): Returns the
GuildMember
object. - getChannel(interaction): Returns the
Channel
object. - getGuild(interaction): Returns the
Guild
object. - addSlashCommand(slashCommand): Adds
SlashCommand
to the database. - reply(interaction, response): Reply to the interaction with either a
string
or anMessageEmbed
. - createAPIMessage(interaction, content): Creates the API content for the reply function. Doesn't need to be called but accessable.
- deleteCommand(commandID): Deletes a
SlashCommand
.