@mxgnus/slashcommands.js
Version:
A simple discord.js v13 & v14 slash command package
357 lines (356 loc) • 16.5 kB
TypeScript
import { ApplicationCommandOptionData, ApplicationCommandOptionType, ChannelType, Client, PermissionResolvable } from 'discord.js';
import { LocalizationMap } from 'discord-api-types/payloads/common';
interface Options {
debug?: boolean;
guildId?: string;
}
declare type SlashcommandOptionTypeString = 'Subcommand' | 'SubcommandGroup' | 'String' | 'Integer' | 'Boolean' | 'User' | 'Channel' | 'Role' | 'Mentionable' | 'Number' | 'Attachment';
declare type SlashcommandOptionType = SlashcommandOptionTypeString | ApplicationCommandOptionType;
declare type SlashcommandChannelType = ChannelType;
declare class Slash {
client: Client;
GuildSlashCommand: typeof GuildSlashCommand;
fetchGuildSlashcommands: typeof fetchGuildSlashcommands;
deleteGuildSlashcommand: typeof deleteGuildSlashcommand;
deleteAllGuildSlashcommands: typeof deleteAllGuildSlashcommands;
Slashcommand: typeof Slashcommand;
fetchSlashcommands: typeof fetchSlashcommands;
fetchSlashcommandById: typeof fetchSlashcommandById;
fetchSlashcommandByName: typeof fetchSlashcommandByName;
deleteSlashcommand: typeof deleteSlashcommand;
deleteAllSlashcommands: typeof deleteAllSlashcommands;
/**
* Initializes the Slash class.
* @param {Client} client - Discord.Client - The discord client.
* @param {Options} clientOptions - Options = {}
* @returns The class instance.
*/
constructor(client: Client, clientOptions?: Options);
}
declare class GuildSlashCommand {
protected name: string | null;
protected description: string | null;
protected options: ApplicationCommandOptionData[];
protected guildId: string | null;
protected type: string | null;
protected dmPermission: boolean | null;
protected nameLocalizations: LocalizationMap | null;
protected descriptionLocalizations: LocalizationMap | null;
protected defaultMemberPermissions: PermissionResolvable | null;
/**
* Creates a new guild slash command.
* @returns The class instance.
*/
constructor();
/**
* This function sets the guildId property of the class instance to the value of the guildId
* parameter, and returns the class instance.
* @param {string} guildId - The ID of the guild.
* @returns The instance of the class.
*/
setGuildId(guildId: string): this;
/**
* This function takes a string, validates it, and then sets the name property of the object to the
* lowercase version of the string.
* @param {string} name - The name of the slash command.
* @returns The instance of the class.
*/
setName(name: string): this;
/**
* The setDescription function takes a string as an argument, validates it, and then sets the
* description property of the object to the value of the argument.
* @param {string} description - The description of the slash command.
* @returns The instance of the class.
*/
setDescription(description: string): this;
/**
* This function takes an array of objects and checks if the objects have a name, type and
* description property. If they don't, it throws an error.
* @param {ApplicationCommandOptionData[]} options - ApplicationCommandOptionData[]
* @returns The instance of the class.
*/
setOptions(options: (ApplicationCommandOptionData | SlashcommandOption)[]): this;
/**
* This function adds an option to the command
* @param {ApplicationCommandOptionData} option - ApplicationCommandOptionData
* @returns The ApplicationCommandData object.
*/
addOption(option: ApplicationCommandOptionData | SlashcommandOption): this;
/**
* This function sets the dmPermission property to the value of the dmPermission parameter, and if
* the type of the dmPermission parameter is not a boolean, it throws an error.
* @param {boolean} dmPermission - boolean - Whether or not slashcommand can be used in DMs.
* @returns The class instance.
*/
setDmPermission(dmPermission: boolean): this;
/**
* This function sets the nameLocalizations property of the object to the value of the
* nameLocalizations parameter.
* @param {LocalizationMap} nameLocalizations - LocalizationMap
* @returns The class instance.
*/
setNameLocalizations(nameLocalizations: LocalizationMap): this;
/**
* This function sets the descriptionLocalizations property of the object to the value of the
* descriptionLocalizations parameter.
* @param {LocalizationMap} descriptionLocalizations - LocalizationMap
* @returns The object itself.
*/
setDescriptionLocalizations(descriptionLocalizations: LocalizationMap): this;
/**
* This function sets the default member permissions for the slash command.
* @param {PermissionResolvable} defaultMemberPermissions - PermissionResolvable
* @returns The instance of the class.
*/
setDefaultMemberPermissions(defaultMemberPermissions: PermissionResolvable): this;
/**
* This function creates a slash command in a guild, and returns the slash command object.
* @returns The slashcommand object.
*/
register(): Promise<import("discord.js").ApplicationCommand<{}>>;
}
declare class Slashcommand {
protected name: string | null;
protected description: string | null;
protected options: ApplicationCommandOptionData[];
protected dmPermission: boolean | null;
protected nameLocalizations: LocalizationMap | null;
protected descriptionLocalizations: LocalizationMap | null;
protected defaultMemberPermissions: PermissionResolvable | null;
/**
* Create a new slashcommand.
* @returns The instance of the class.
*/
constructor();
/**
* This function takes a string, validates it, and then sets the name property of the object to the
* lowercase version of the string.
* @param {string} name - The name of the new slash command.
* @returns The instance of the class.
*/
setName(name: string): this;
/**
* The function takes a string as an argument, validates it, and then sets the description property
* of the object to the value of the argument
* @param {string} description - The description of the slashcommand.
* @returns The instance of the class.
*/
setDescription(description: string): this;
/**
* This function takes an array of objects and checks if the objects have a name, type and
* description property. If they don't, it throws an error.
* @param {ApplicationCommandOptionData[]} options - ApplicationCommandOptionData[]
* @returns The instance of the class.
*/
setOptions(options: (ApplicationCommandOptionData | SlashcommandOption)[]): this;
/**
* This function adds an option to the command
* @param {ApplicationCommandOptionData} option - ApplicationCommandOptionData
* @returns The ApplicationCommandData object.
*/
addOption(option: ApplicationCommandOptionData | SlashcommandOption): this;
/**
* This function sets the dmPermission property to the value of the dmPermission parameter, and if
* the type of the dmPermission parameter is not a boolean, it throws an error.
* @param {boolean} dmPermission - boolean - Whether or not slashcommand can be used in DMs.
* @returns The class instance.
*/
setDmPermission(dmPermission: boolean): this;
/**
* This function sets the nameLocalizations property of the object to the value of the
* nameLocalizations parameter.
* @param {LocalizationMap} nameLocalizations - LocalizationMap
* @returns The instance of the class.
*/
setNameLocalizations(nameLocalizations: LocalizationMap): this;
/**
* This function sets the descriptionLocalizations property of the object to the value of the
* descriptionLocalizations parameter.
* @param {LocalizationMap} descriptionLocalizations - LocalizationMap
* @returns The instance of the class.
*/
setDescriptionLocalizations(descriptionLocalizations: LocalizationMap): this;
/**
* This function sets the default member permissions for the slash command.
* @param {PermissionResolvable} defaultMemberPermissions - PermissionResolvable
* @returns The instance of the class.
*/
setDefaultMemberPermissions(defaultMemberPermissions: PermissionResolvable): this;
/**
* Creates the slash command.
* @returns The slashcommand object.
*/
register(): Promise<import("discord.js").ApplicationCommand<{
guild: import("discord.js").GuildResolvable;
}> | undefined>;
}
declare class SlashCommandOptionChoice {
name: string | number | boolean | null;
value: string | number | boolean | null;
nameLocalizations: LocalizationMap | null;
/**
* Create a new slash command option choice.
* @returns The object that is being created.
*/
constructor();
/**
* The setName function takes a string, number, or boolean as an argument and sets the name property
* of the Choice object to the value of the argument.
* @param {string | number | boolean} name - The name of the choice.
* @returns The instance of the class.
*/
setName(name: string | number | boolean): this;
/**
* This function sets the value of the choice to the value passed in, and returns the choice.
* @param {string | number | boolean} value - string | number | boolean
* @returns The value of the property "value"
*/
setValue(value: string | number | boolean): this;
/**
* This function sets the nameLocalizations property of the object to the value of the
* nameLocalizations parameter.
* @param {LocalizationMap} nameLocalizations - LocalizationMap
* @returns The object itself.
*/
setNameLocalizations(nameLocalizations: LocalizationMap): this;
}
declare class SlashcommandOption {
name: string | null;
description: string | null;
type: ApplicationCommandOptionType | null;
required: boolean;
autocomplete: boolean;
channelTypes?: SlashcommandChannelType[];
maxValue?: number;
minValue?: number;
choices?: SlashCommandOptionChoice[];
nameLocalizations: LocalizationMap | null;
descriptionLocalizations: LocalizationMap | null;
options: ApplicationCommandOptionData[] | null;
/**
* Creates a new SlashcommandOption object.
* @returns The object that is being created.
*/
constructor();
/**
* This function takes a string, validates it, and then sets the name property of the object to the
* lowercase version of the string.
* @param {string} name - The name of the new user.
* @returns The instance of the class.
*/
setName(name: string): this;
/**
* The function takes a string as an argument, validates it, and then sets the description property
* of the object to the value of the argument
* @param {string} description - The description of the task.
* @returns The instance of the class.
*/
setDescription(description: string): this;
/**
* This function sets the type of the option to the type passed in as a parameter and returns the
* option.
* @param {SlashcommandOptionType} type - The type of option.
* @returns The object itself.
*/
setType(type: SlashcommandOptionType): this;
/**
* This function sets the required property of the class to the value passed in.
* @param {boolean} required - boolean
* @returns The instance of the class.
*/
setRequired(required: boolean): this;
/**
* This function sets the autocomplete property of the class to the value passed in as a parameter.
* @param {boolean} autocomplete - boolean
* @returns The object itself.
*/
setAutocomplete(autocomplete: boolean): this;
/**
* This function sets the allowed channel types for the slash command.
* @param {SlashcommandChannelType[]} channelTypes - SlashcommandChannelType[]
* @returns The object itself.
*/
setChannelTypes(channelTypes: SlashcommandChannelType[]): this;
/**
* This function sets the maxValues property of the object to the value passed in as a parameter and
* returns the object.
* @param {number} maxValues - The maximum number of values to return.
* @returns The object itself.
*/
setMaxValues(maxValues: number): this;
/**
* This function sets the minValue property of the object to the value passed in as a parameter and
* returns the object.
* @param {number} minValue - The minimum value of the range.
* @returns The object itself.
*/
setMinValue(minValue: number): this;
/**
* This function sets the choices for the slash command
* @param {SlashCommandOptionChoice[]} choices - An array of SlashCommandOptionChoice objects.
* @returns The object itself.
*/
setChoices(choices: SlashCommandOptionChoice[]): this;
/**
* This function sets the nameLocalizations property of the object to the value of the
* nameLocalizations parameter.
* @param {LocalizationMap} nameLocalizations - LocalizationMap
* @returns The instance of the class.
*/
setNameLocalizations(nameLocalizations: LocalizationMap): this;
/**
* This function sets the descriptionLocalizations property of the object to the value of the
* descriptionLocalizations parameter.
* @param {LocalizationMap} descriptionLocalizations - LocalizationMap
* @returns The instance of the class.
*/
setDescriptionLocalizations(descriptionLocalizations: LocalizationMap): this;
/**
* It takes an array of objects
* @param {(ApplicationCommandOptionData| SlashcommandOption)[]} options -
* (ApplicationCommandOptionData| SlashcommandOption)[]
* @returns The object itself.
*/
setOptions(options: (ApplicationCommandOptionData | SlashcommandOption)[]): this;
/**
* This function adds an option to the option
* @param {ApplicationCommandOptionData | SlashcommandOption} option - ApplicationCommandOptionData
* | SlashcommandOption
* @returns The object itself.
*/
addOption(option: ApplicationCommandOptionData | SlashcommandOption): this;
}
declare function fetchGuildSlashcommands({ guildId }?: {
guildId: string;
}): Promise<import("discord.js").Collection<string, import("discord.js").ApplicationCommand<{}>> | undefined>;
declare function fetchSlashcommandById({ id, guildId, }: {
id: string;
guildId?: string;
}): Promise<import("discord.js").ApplicationCommand<{
guild: import("discord.js").GuildResolvable;
}> | undefined>;
declare function fetchSlashcommands(): Promise<import("discord.js").Collection<string, import("discord.js").ApplicationCommand<{
guild: import("discord.js").GuildResolvable;
}>> | undefined>;
declare function fetchSlashcommandByName({ name, guildId, }: {
name: string;
guildId?: string;
}): Promise<import("discord.js").ApplicationCommand<{
guild: import("discord.js").GuildResolvable;
}> | null>;
declare function deleteGuildSlashcommand({ guildId, name, id, }?: {
guildId: string;
name?: string;
id?: string;
}): Promise<import("discord.js").ApplicationCommand<{}> | undefined>;
declare function deleteSlashcommand({ name, id, }?: {
name?: string;
id?: string;
}): Promise<import("discord.js").ApplicationCommand<{
guild: import("discord.js").GuildResolvable;
}> | undefined>;
declare function deleteAllGuildSlashcommands({ guildId, }?: {
guildId: string;
}): Promise<(import("discord.js").ApplicationCommand<{}> | null)[] | undefined>;
declare function deleteAllSlashcommands(): Promise<void[] | undefined>;
export { Slash, Slashcommand, SlashcommandOption, SlashCommandOptionChoice, GuildSlashCommand, fetchGuildSlashcommands, fetchSlashcommands, fetchSlashcommandById, fetchSlashcommandByName, deleteGuildSlashcommand, deleteSlashcommand, deleteAllGuildSlashcommands, deleteAllSlashcommands, };