A simple way to interact and manage discord slash-commands.
This module has been forked to be adapted to the scripts of the Tiny Pudding Server repositories. The first version was made by https://github.com/MatteZ02/discord-interactions.
You need to choose whether to type a Bot Token or a User Token.
const interactions = require("@tinypudding/discord-slash-commands");
const client = new interactions.Client({
bot_token: "you unique bot token",
client_id: "your bots user id",
user_token: "you unique user token"
});client.getCommands().then(console.log).catch(console.error);Will create a new command and log its data. If a command with this name already exist will that be overwritten.
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);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
getCommandsOptions- List of options can be found here.
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.
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.
Properties marked with ? are optional.
{
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,// Type for this option. for a list of types see https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoptiontype
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;
}{
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"
}You can find a list of Data Models and Types from here.
You can setup a webhook-based interaction. You can read more about how to do this from the documentation.
channel: Discord.TextChannel;// The channel where this interaction occured
guild: Discord.Guild;// The guild where this interaction occured
member: Discord.GuildMember | null;// The guild member who issued the interaction (will be null if we cannot obtain a guildMember)
author: Discord.User | null;// The user who issued the interaction (will be null if we cannot obtain an user)
name: string;// name of this command
content: string;// content of this command (everything after the main command name)
createdTimestamp: number;// timestamp of this command being used
options: { value: string; name: string }[] | null;// list of options this user inputted to the command