discord-slash-commands-client
An easy way to create and manage discord slash-commands.
Support
You can contact us on our Discord server
Usage
const { Client } = require("discord-slash-commands-client");
const client = new Client(
"you unique bot token",
"your bots user id"
);
client.getCommands().then(console.log).catch(console.error);
client
.createCommand({
name: "unique command name",
description: "description for this unique command",
})
.then(console.log)
.catch(console.error);
client
.editCommand(
{ name: "new command name", description: "new command description" },
"id of the command you wish to edit"
)
.then(console.log)
.catch(console.error);
client
.deleteCommand("id of the command you wish to delete")
.then(console.log)
.catch(console.error);
API
Passing a guildID is optional. Doing so will make the command only be available on that guild.
Guild commands update instantly. We recommend you use guild commands for quick testing, and global commands when they're ready for public use.
Discord api documentation on slash commands
getCommands(options: getCommandOptions) returns Promise< array of ApplicationOptions>
getCommandsOptions
- List of options can be found here.
createCommand(options: ApplicationCommandOptions, guildID?: string) returns Promise
ApplicationOptions
- List of options can be found here.guildID
- guild to create this command on.
editCommand(options: ApplicationCommandOptions, commandID: string, guildID?: string) returns Promise
ApplicationOptions
- List of options can be found here.commandID
- ID of the command you wish to edit.guildID
- If the command is a part of a guild you must pass the guildID here.
deleteCommand(commandID: string, guildID?: string) returns Promise
commandID
- ID of the command you wish to delete.guildID
- If the command is a part of a guild you must pass the guildID here.
getCommandPermissions(guildID: string, commandID?: string) returns Promise<GuildApplicationCommandPermissions[] | GuildApplicationCommandPermissions>;
guildID
- the guild id to get permissions forcommandID
- ID of the command you wish to get permissions for
editCommandPermissions(permissions: ApplicationCommandPermissions[], guildID: string, commandID: string) returns Promise
ApplicationCommandPermissions
- list of permissionsguildID
- The guild ID the permissions should apply forcommandID
- The command ID the permissions should apply for
Options
Properties marked with ?
are optional.
ApplicationCommandOption
{
name: "name of this unique command",
description: "description for this unique command",
options?: [
{
name: "name of this option",
description: "description for this option",
type: 1,
default?: true,
required?: true,
choices?: [
{
name: "string to prefill for this choice",
value: "value of this choice that will be returned when command is used."
}
]
}
]
}
{
name: "name of the command";
description: "description of the command";
options?: Array of ApplicationCommandOption;
}
getCommandsOptions
{
commandID?: "id of the command you wish to get",
guildID?: "if the command is a part of a guild u should put the guild id here"
}
Permissions
interface ApplicationCommandPermissions {
id: string;
type: 1 | 2;
permission: boolean;
}
interface GuildApplicationCommandPermissions {
id: string;
application_id: string;
guild_id: string;
permissions: ApplicationCommandPermissions[];
}
Types
You can find a list of Data Models and Types from here
Interaction with the command
To receive an interaction with the command (when an user uses the command) there are 2 options.
- You can setup a webhook-based interaction. You can read more about how to do this from the documentation
- If you're using discord.js you can use my own fork to receive events for interaction.
Events
We'll cover using the 2nd option.
Replace your current discord.js with my fork npm i https://github.com/MatteZ02/discord.js
You can listen to the interactionCreate event which will fire every time someone uses any of the commands created for your bot.
Usage with djs
const Discord = require("discord.js");
const interactions = require("discord-slash-commands-client");
const client = new Discord.Client();
const token = "Your unique bot token";
client.interactions = new interactions.Client(token, "You bots user id");
client.on("ready", () => {
console.log("Client is ready!");
client.interactions
.createCommand({
name: "ping",
description: "ping pong",
})
.then(console.log)
.catch(console.error);
});
client.on("interactionCreate", async (interaction) => {
if (interaction.name === "ping") {
await interaction.reply("Pong");
const messageId = await interaction.reply({
content: "Follow up message",
embeds: [new MessageEmbed().setDescription("Follow up test")],
});
setTimeout(() => {
interaction.delete();
interaction.edit("Edited follow up message", messageId);
}, 5000);
}
});
client.login(token);
interaction example response
id: string;
token: string;
channel: Discord.TextChannel;
guild: Discord.Guild;
member: Discord.GuildMember | null;
author: Discord.User | null;
name: string;
content: string;
createdTimestamp: number;
options: { value: string; name: string }[] | null;
reply: (
input?: string | MessageEmbed[] | { content: string; embeds: MessageEmbed[] },
ephemeral?: boolean,
) => Promise<string>;
edit: (
input?: string | MessageEmbed[] | { content: string; embeds: MessageEmbed[] },
messageId?: string,
) => Promise<void>;
thinking: (ephemeral?: boolean) => Promise<void>;
delete: (messageId?: string) => Promise<void>;