diff --git a/index.d.ts b/index.d.ts index e8931b9d8..3e8264e21 100644 --- a/index.d.ts +++ b/index.d.ts @@ -73,7 +73,6 @@ declare namespace Eris { // Interaction type InteractionType = 1 | 2 | 3; type InteractionResponseType = 1 | 4 | 5 | 6 | 7; - type SlashCommandOptionType = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9; type InteractionDataOptions = { name: string; @@ -97,6 +96,45 @@ declare namespace Eris { type InteractionWebhookContent = Pick; + //Slash Commands + type SlashCommandType = 1 | 2 | 3; + + type SlashCommandOptionType = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10; + + type SlashCommandOptions = { + type: SlashCommandOptionType; + name: string; + description: string; + required?: boolean; + choices?: { name: string; value: string | number}; + }; + + type SlashCommand = { + id: string; + application_id: string; + guild_id?: string; + name: string; + description: string; + options?: SlashCommandOptions[]; + type?: SlashCommandType; + defaultPermission?: boolean; + }; + + type SlashCommandStructure = Omit; + + type SlashCommandPermissions = { + id: string; + type: 1 | 2; + permission: boolean; + }; + + type GuildSlashCommandPermissions = { + id: string; + application_id: string; + guild_id: string; + permissions?: SlashCommandPermissions[]; + }; + // Permission type PermissionType = 0 | 1; @@ -1363,6 +1401,27 @@ declare namespace Eris { DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE: 5; DEFERRED_UPDATE_MESSAGE: 6; UPDATE_MESSAGE: 7; + } + CommandOptionTypes: { + SUB_COMMAND: 1; + SUB_COMMAND_GROUP: 2; + STRING: 3; + INTEGER: 4; + BOOLEAN: 5; + USER: 6; + CHANNEL: 7; + ROLE: 8; + MENTIONABLE: 9; + NUMBER: 10; + }; + CommandPermissionTypes: { + ROLE: 1; + USER: 2; + }; + CommandTypes: { + COMMAND: 1; + USER: 2; + MESSAGE: 3; }; } @@ -1550,6 +1609,9 @@ declare namespace Eris { addRelationship(userID: string, block?: boolean): Promise; addSelfPremiumSubscription(token: string, plan: string): Promise; banGuildMember(guildID: string, userID: string, deleteMessageDays?: number, reason?: string): Promise; + bulkEditCommandPermissions(guildID: string, permissions: SlashCommandPermissions[]): Promise; + bulkEditCommands(commands: SlashCommandStructure[]): Promise; + bulkEditGuildCommands(guildID: string, commands: SlashCommandStructure[]): Promise; closeVoiceConnection(guildID: string): void; connect(): Promise; createChannel(guildID: string, name: string): Promise; @@ -1661,8 +1723,10 @@ declare namespace Eris { options: { name: string; avatar?: string | null }, reason?: string ): Promise; + createCommand(command: SlashCommandStructure): Promise; createGroupChannel(userIDs: string[]): Promise; createGuild(name: string, options?: CreateGuildOptions): Promise; + createGuildCommand(guildID: string, command: SlashCommandStructure): Promise; createGuildEmoji(guildID: string, options: EmojiOptions, reason?: string): Promise; createGuildFromTemplate(code: string, name: string, icon?: string): Promise; createGuildTemplate(guildID: string, name: string, description?: string | null): Promise; @@ -1672,7 +1736,9 @@ declare namespace Eris { crosspostMessage(channelID: string, messageID: string): Promise; deleteChannel(channelID: string, reason?: string): Promise; deleteChannelPermission(channelID: string, overwriteID: string, reason?: string): Promise; + deleteCommand(commandID: string): Promise; deleteGuild(guildID: string): Promise; + deleteGuildCommand(guildID: string, commandID: string): Promise; deleteGuildDiscoverySubcategory(guildID: string, categoryID: string, reason?: string): Promise; deleteGuildEmoji(guildID: string, emojiID: string, reason?: string): Promise; deleteGuildIntegration(guildID: string, integrationID: string): Promise; @@ -1703,7 +1769,10 @@ declare namespace Eris { reason?: string ): Promise; editChannelPosition(channelID: string, position: number, options?: EditChannelPositionOptions): Promise; + editCommand(commandID: string, command: SlashCommandStructure): Promise; + editCommandPermissions(guildID: string, commandID: string, permissions: SlashCommandPermissions[]): Promise; editGuild(guildID: string, options: GuildOptions, reason?: string): Promise; + editGuildCommand(guildID: string, commandID: string, command: SlashCommandStructure): Promise; editGuildDiscovery(guildID: string, options?: DiscoveryOptions): Promise; editGuildEmoji( guildID: string, @@ -1757,6 +1826,9 @@ declare namespace Eris { getChannel(channelID: string): AnyChannel; getChannelInvites(channelID: string): Promise; getChannelWebhooks(channelID: string): Promise; + getCommand(commandID: string): Promise; + getCommandPermissions(guildID: string, commandID: string): Promise; + getCommands(): Promise; getDiscoveryCategories(): Promise; getDMChannel(userID: string): Promise; getEmojiGuild(emojiID: string): Promise; @@ -1766,6 +1838,9 @@ declare namespace Eris { getGuildAuditLogs(guildID: string, limit?: number, before?: string, actionType?: number, userID?: string): Promise; getGuildBan(guildID: string, userID: string): Promise<{ reason?: string; user: User }>; getGuildBans(guildID: string): Promise<{ reason?: string; user: User }[]>; + getGuildCommand(guildID: string, commandID: string): Promise; + getGuildCommandPermissions(guildID: string): Promise; + getGuildCommands(guildID: string): Promise; getGuildDiscovery(guildID: string): Promise; /** @deprecated */ getGuildEmbed(guildID: string): Promise; @@ -2057,6 +2132,7 @@ declare namespace Eris { addDiscoverySubcategory(categoryID: string, reason?: string): Promise; addMemberRole(memberID: string, roleID: string, reason?: string): Promise; banMember(userID: string, deleteMessageDays?: number, reason?: string): Promise; + bulkEditCommands(commands: SlashCommandStructure[]): Promise; createChannel(name: string): Promise; createChannel(name: string, type: 0, options?: CreateChannelOptions): Promise; createChannel(name: string, type: 2, options?: CreateChannelOptions): Promise; @@ -2079,10 +2155,12 @@ declare namespace Eris { createChannel(name: string, type: 13, reason?: string, options?: CreateChannelOptions | string): Promise; /** @deprecated */ createChannel(name: string, type?: number, reason?: string, options?: CreateChannelOptions | string): Promise; + createCommand(command: SlashCommandStructure): Promise; createEmoji(options: { image: string; name: string; roles?: string[] }, reason?: string): Promise; createRole(options: RoleOptions | Role, reason?: string): Promise; createTemplate(name: string, description?: string | null): Promise; delete(): Promise; + deleteCommand(commandID: string): Promise; deleteDiscoverySubcategory(categoryID: string, reason?: string): Promise; deleteEmoji(emojiID: string, reason?: string): Promise; deleteIntegration(integrationID: string): Promise; @@ -2093,6 +2171,8 @@ declare namespace Eris { dynamicIconURL(format?: ImageFormat, size?: number): string; dynamicSplashURL(format?: ImageFormat, size?: number): string; edit(options: GuildOptions, reason?: string): Promise; + editCommand(commandID: string, command: SlashCommandStructure): Promise; + editCommandPermissions(permissions: SlashCommandPermissions[]): Promise; editDiscovery(options?: DiscoveryOptions): Promise; editEmoji(emojiID: string, options: { name: string; roles?: string[] }, reason?: string): Promise; editIntegration(integrationID: string, options: IntegrationOptions): Promise; @@ -2111,6 +2191,9 @@ declare namespace Eris { getAuditLogs(limit?: number, before?: string, actionType?: number, userID?: string): Promise; getBan(userID: string): Promise<{ reason?: string; user: User }>; getBans(): Promise<{ reason?: string; user: User }[]>; + getCommand(commandID: string): Promise; + getCommandPermissions(): Promise; + getCommands(): Promise; getDiscovery(): Promise; /** @deprecated */ getEmbed(): Promise; diff --git a/lib/Client.js b/lib/Client.js index a27fca1f6..8a019a80b 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -337,6 +337,58 @@ class Client extends EventEmitter { }); } + /** + * Edits command permissions for a multiple commands in a guild. + * Note: You can only add up to 10 permission overwrites for a command. + * @arg {String} guildID The guild id + * @arg {Array} permissions An array of [partial guild command permissions](https://discord.com/developers/docs/interactions/slash-commands#application-command-permissions-object-guild-application-command-permissions-structure) + * @returns {Promise>} Returns an array of [GuildApplicationCommandPermissions](https://discord.com/developers/docs/interactions/slash-commands#application-command-permissions-object-guild-application-command-permissions-structure) objects. + */ + bulkEditCommandPermissions(guildID, permissions) { + if(!guildID) { + throw new Error("You must provide an id of the guild whose permissions you want to edit."); + } + + return this.requestHandler.request("PUT", Endpoints.GUILD_COMMAND_PERMISSIONS(this.application.id, guildID), true, {permissions}); + } + + /** + * Bulk create/edit global slash commands + * @arg {Array} commands An array of [Command objects](https://discord.com/developers/docs/interactions/slash-commands#application-command-object) + * @returns {Promise} Resolves with an array of commands objects + */ + bulkEditCommands(commands) { + for(const command of commands) { + if(!command.name || !command.description) { + throw new Error("You must define a command name and description."); + } + command.name = command.name.toLowerCase(); + if(!command.name.match(/^[\w-]{1,32}$/)) { + throw new Error("Command names must match the regular expression \"^[\\w-]{1,32}$\""); + } + } + return this.requestHandler.request("PUT", Endpoints.COMMANDS(this.application.id), true, commands); + } + + /** + * Bulk create/edit guild slash commands + * @arg {String} guildID Guild id to create the commands in + * @arg {Array} commands An array of [Command objects](https://discord.com/developers/docs/interactions/slash-commands#application-command-object) + * @returns {Promise} Resolves with an array of commands objects + */ + bulkEditGuildCommands(guildID, commands) { + for(const command of commands) { + if(!command.name || !command.description) { + throw new Error("You must define a command name and description."); + } + command.name = command.name.toLowerCase(); + if(!command.name.match(/^[\w-]{1,32}$/)) { + throw new Error("Command names must match the regular expression \"^[\\w-]{1,32}$\""); + } + } + return this.requestHandler.request("PUT", Endpoints.GUILD_COMMANDS(this.application.id, guildID), true, commands); + } + /** * Closes a voice connection with a guild ID * @arg {String} guildID The ID of the guild @@ -478,6 +530,27 @@ class Client extends EventEmitter { return this.requestHandler.request("POST", Endpoints.CHANNEL_WEBHOOKS(channelID), true, options); } + /** + * Create a global slash command + * @arg {Object} command A command object + * @arg {String} command.name The command name + * @arg {String} command.description The command description + * @arg {Array} [command.options] An array of [command options](https://discord.com/developers/docs/interactions/slash-commands#application-command-object-application-command-option-structure) + * @arg {Number} [type] CURRENTLY IN PRIVATE BETA The type of slash command, 1 for slash command, 2 for user and 3 for message (1 by default) + * @arg {Boolean} [command.defaultPermission] Whether the command is enabled by default when the app is added to a guild + * @returns {Promise} Resolves with a commands object + */ + createCommand(command) { + if(!command.name || !command.description) { + throw new Error("You must define a command name and description."); + } + command.name = command.name.toLowerCase(); + if(!command.name.match(/^[\w-]{1,32}$/)) { + throw new Error("Command names must match the regular expression \"^[\\w-]{1,32}$\""); + } + return this.requestHandler.request("POST", Endpoints.COMMANDS(this.application.id), true, command); + } + /** * [USER ACCOUNT] Create a group channel with other users * @arg {Array} userIDs The IDs of the other users @@ -526,6 +599,28 @@ class Client extends EventEmitter { }).then((guild) => new Guild(guild, this)); } + /** + * Create a guild slash command + * @arg {String} guildID The ID of the guild to create the command in + * @arg {Object} command A command object + * @arg {String} command.name The command name + * @arg {String} command.description The command description + * @arg {Array} [command.options] An array of [command options](https://discord.com/developers/docs/interactions/slash-commands#application-command-object-application-command-option-structure) + * @arg {Number} [type] CURRENTLY IN PRIVATE BETA The type of slash command, 1 for slash command, 2 for user and 3 for message (1 by default) + * @arg {Boolean} [command.defaultPermission] Whether the command is enabled by default when the app is added to a guild + * @returns {Promise} Resolves with a commands object + */ + createGuildCommand(guildID, command) { + if(!command.name || !command.description) { + throw new Error("You must define a command name and description."); + } + command.name = command.name.toLowerCase(); + if(!command.name.match(/^[\w-]{1,32}$/)) { + throw new Error("Command names must match the regular expression \"^[\\w-]{1,32}$\""); + } + return this.requestHandler.request("POST", Endpoints.GUILD_COMMANDS(this.application.id, guildID), true, command); + } + /** * Create a guild emoji object * @arg {String} guildID The ID of the guild to create the emoji in @@ -724,6 +819,18 @@ class Client extends EventEmitter { }); } + /** + * Delete a global slash command + * @arg {String} commandID The command id + * @returns {Promise} + */ + deleteCommand(commandID) { + if(!commandID) { + throw new Error("You must provide an id of the command to delete."); + } + return this.requestHandler.request("DELETE", Endpoints.COMMAND(this.application.id, commandID), true); + } + /** * Delete a guild (bot user must be owner) * @arg {String} guildID The ID of the guild @@ -733,6 +840,22 @@ class Client extends EventEmitter { return this.requestHandler.request("DELETE", Endpoints.GUILD(guildID), true); } + /** + * Delete a guild slash command + * @arg {String} guildID The guild id + * @arg {String} commandID The command id + * @returns {Promise} + */ + deleteGuildCommand(guildID, commandID) { + if(!guildID) { + throw new Error("You must provide an id of the guild which the command is in."); + } + if(!commandID) { + throw new Error("You must provide an id of the command to delete."); + } + return this.requestHandler.request("DELETE", Endpoints.GUILD_COMMAND(this.application.id, guildID, commandID), true); + } + /** * Delete a guild discovery subcategory * @arg {String} guildID The ID of the guild @@ -1034,6 +1157,45 @@ class Client extends EventEmitter { }))); } + /** + * Edit a global slash command + * @arg {String} commandID The command id + * @arg {Object} command A command object + * @arg {String} command.name The command name + * @arg {String} command.description The command description + * @arg {Array} [command.options] An array of [command options](https://discord.com/developers/docs/interactions/slash-commands#application-command-object-application-command-option-structure) + * @arg {Boolean} [command.defaultPermission] Whether the command is enabled by default when the app is added to a guild + * @returns {Promise} Resolves with a commands object + */ + editCommand(commandID, command) { + if(!commandID) { + throw new Error("You must provide an id of the command to edit."); + } + command.name = command.name.toLowerCase(); + if(!command.name.match(/^[\w-]{1,32}$/)) { + throw new Error("Command names must match the regular expression \"^[\\w-]{1,32}$\""); + } + return this.requestHandler.request("PATCH", Endpoints.COMMAND(this.application.id, commandID), true, command); + } + + /** + * Edits command permissions for a specific command in a guild. + * Note: You can only add up to 10 permission overwrites for a command. + * @arg {String} guildID The guild id + * @arg {String} commandID The command id + * @arg {Array} permissions An array of [permissions objects](https://discord.com/developers/docs/interactions/slash-commands#application-command-permissions-object-application-command-permissions-structure) + * @returns {Promise} Resolves with a [GuildApplicationCommandPermissions](https://discord.com/developers/docs/interactions/slash-commands#application-command-permissions-object-guild-application-command-permissions-structure) object. + */ + editCommandPermissions(guildID, commandID, permissions) { + if(!guildID) { + throw new Error("You must provide an id of the guild whose permissions you want to edit."); + } + if(!commandID) { + throw new Error("You must provide an id of the command whose permissions you want to edit."); + } + return this.requestHandler.request("PUT", Endpoints.COMMAND_PERMISSIONS(this.application.id, guildID, commandID), true, {permissions}); + } + /** * Edit a guild * @arg {String} guildID The ID of the guild @@ -1085,6 +1247,27 @@ class Client extends EventEmitter { }).then((guild) => new Guild(guild, this)); } + /** + * Edit a guild slash command + * @arg {String} guildID The guild id + * @arg {Object} command A command object + * @arg {String} command.name The command name + * @arg {String} command.description The command description + * @arg {Array} [command.options] An array of [command options](https://discord.com/developers/docs/interactions/slash-commands#application-command-object-application-command-option-structure) + * @arg {Boolean} [command.defaultPermission] Whether the command is enabled by default when the app is added to a guild + * @returns {Promise} Resolves with a commands object + */ + editGuildCommand(guildID, commandID, command) { + if(!commandID) { + throw new Error("You must provide an id of the command to edit."); + } + command.name = command.name.toLowerCase(); + if(!command.name.match(/^[\w-]{1,32}$/)) { + throw new Error("Command names must match the regular expression \"^[\\w-]{1,32}$\""); + } + return this.requestHandler.request("PATCH", Endpoints.GUILD_COMMAND(this.application.id, guildID, commandID), true, command); + } + /** * Edit a guild's discovery data * @arg {String} guildID The ID of the guild @@ -1648,6 +1831,42 @@ class Client extends EventEmitter { return this.requestHandler.request("GET", Endpoints.CHANNEL_WEBHOOKS(channelID), true); } + /** + * Get a global slash command + * @arg {String} commandID The command id + * @returns {Promise} Resolves with an application command object. + */ + getCommand(commandID) { + if(!commandID) { + throw new Error("You must provide an id of the command to get."); + } + return this.requestHandler.request("GET", Endpoints.COMMAND(this.application.id, commandID), true); + } + + /** + * Get the a guild's slash command permissions + * @arg {String} guildID The guild id + * @arg {String} commandID The command id + * @returns {Promise} Resolves with a guild application command permissions object. + */ + getCommandPermissions(guildID, commandID) { + if(!guildID) { + throw new Error("You must provide an id of the guild whose permissions you want to get."); + } + if(!commandID) { + throw new Error("You must provide an id of the command whose permissions you want to get."); + } + return this.requestHandler.request("GET", Endpoints.COMMAND_PERMISSIONS(this.application.id, guildID, commandID), true); + } + + /** + * Get the global slash commands + * @returns {Promise>} Resolves with an array of application command objects. + */ + getCommands() { + return this.requestHandler.request("GET", Endpoints.COMMANDS(this.application.id), true); + } + /** * Get a list of discovery categories * @returns {Promise>} @@ -1773,6 +1992,40 @@ class Client extends EventEmitter { }); } + /** + * Get a guild slash command + * @arg {String} guildID The guild id + * @arg {String} commandID The command id + * @returns {Promise} Resolves with an command object. + */ + getGuildCommand(guildID, commandID) { + if(!commandID) { + throw new Error("You must provide an id of the command to get."); + } + return this.requestHandler.request("GET", Endpoints.GUILD_COMMAND(this.application.id, guildID, commandID), true); + } + + /** + * Get the all of a guild's slash command permissions + * @arg {String} guildID The guild id + * @returns {Promise>} Resolves with an array of guild application command permissions objects. + */ + getGuildCommandPermissions(guildID) { + if(!guildID) { + throw new Error("You must provide an id of the guild whose permissions you want to get."); + } + return this.requestHandler.request("GET", Endpoints.GUILD_COMMAND_PERMISSIONS(this.application.id, guildID), true); + } + + /** + * Get a guild's slash commands + * @arg {String} guildID The guild id + * @returns {Promise>} Resolves with an array of command objects. + */ + getGuildCommands(guildID) { + return this.requestHandler.request("GET", Endpoints.GUILD_COMMANDS(this.application.id, guildID), true); + } + /** * Get a guild's discovery object * @arg {String} guildID The ID of the guild diff --git a/lib/Constants.js b/lib/Constants.js index 7a5544df8..6ddc01aa1 100644 --- a/lib/Constants.js +++ b/lib/Constants.js @@ -291,3 +291,26 @@ module.exports.InteractionResponseTypes = { DEFERRED_UPDATE_MESSAGE: 6, UPDATE_MESSAGE: 7 }; +module.exports.CommandOptionTypes = { + SUB_COMMAND: 1, + SUB_COMMAND_GROUP: 2, + STRING: 3, + INTEGER: 4, + BOOLEAN: 5, + USER: 6, + CHANNEL: 7, + ROLE: 8, + MENTIONABLE: 9, + NUMBER: 10 +}; + +module.exports.CommandPermissionTypes = { + ROLE: 1, + USER: 2 +}; + +module.exports.CommandTypes = { + COMMAND: 1, + USER: 2, + MESSAGE: 3 +}; diff --git a/lib/rest/Endpoints.js b/lib/rest/Endpoints.js index 1023f6470..79dd0aa08 100644 --- a/lib/rest/Endpoints.js +++ b/lib/rest/Endpoints.js @@ -7,6 +7,9 @@ module.exports.CDN_URL = "https://cdn.discordapp.com"; module.exports.CLIENT_URL = "https://discord.com"; module.exports.ORIGINAL_INTERACTION_RESPONSE = (appID, interactToken) => `/webhooks/${appID}/${interactToken}`; +module.exports.COMMAND = (applicationID, commandID) => `/applications/${applicationID}/commands/${commandID}`; +module.exports.COMMANDS = (applicationID) => `/applications/${applicationID}/commands`; +module.exports.COMMAND_PERMISSIONS = (applicationID, guildID, commandID) => `/applications/${applicationID}/guilds/${guildID}/commands/${commandID}/permissions`; module.exports.CHANNEL = (chanID) => `/channels/${chanID}`; module.exports.CHANNEL_BULK_DELETE = (chanID) => `/channels/${chanID}/messages/bulk-delete`; module.exports.CHANNEL_CALL_RING = (chanID) => `/channels/${chanID}/call/ring`; @@ -37,6 +40,9 @@ module.exports.GUILD_AUDIT_LOGS = (guildID) module.exports.GUILD_BAN = (guildID, memberID) => `/guilds/${guildID}/bans/${memberID}`; module.exports.GUILD_BANS = (guildID) => `/guilds/${guildID}/bans`; module.exports.GUILD_CHANNELS = (guildID) => `/guilds/${guildID}/channels`; +module.exports.GUILD_COMMAND = (applicationID, guildID, commandID) => `/applications/${applicationID}/guilds/${guildID}/commands/${commandID}`; +module.exports.GUILD_COMMAND_PERMISSIONS = (applicationID, guildID) => `/applications/${applicationID}/guilds/${guildID}/commands/permissions`; +module.exports.GUILD_COMMANDS = (applicationID, guildID) => `/applications/${applicationID}/guilds/${guildID}/commands`; module.exports.GUILD_DISCOVERY = (guildID) => `/guilds/${guildID}/discovery-metadata`; module.exports.GUILD_DISCOVERY_CATEGORY = (guildID, categoryID) => `/guilds/${guildID}/discovery-categories/${categoryID}`; module.exports.GUILD_EMOJI = (guildID, emojiID) => `/guilds/${guildID}/emojis/${emojiID}`; diff --git a/lib/structures/Guild.js b/lib/structures/Guild.js index bbde2d607..abf0d79b9 100644 --- a/lib/structures/Guild.js +++ b/lib/structures/Guild.js @@ -339,6 +339,25 @@ class Guild extends Base { return this._client.banGuildMember.call(this._client, this.id, userID, deleteMessageDays, reason); } + /** + * Edits command permissions for a multiple commands in a guild. + * Note: You can only add up to 10 permission overwrites for a command. + * @arg {Array} permissions An array of [partial guild command permissions](https://discord.com/developers/docs/interactions/slash-commands#application-command-permissions-object-guild-application-command-permissions-structure) + * @returns {Promise>} Returns an array of [GuildApplicationCommandPermissions](https://discord.com/developers/docs/interactions/slash-commands#application-command-permissions-object-guild-application-command-permissions-structure) objects. + */ + bulkEditCommandPermissions(permissions) { + return this._client.bulkEditCommandPermissions.call(this._client, this.id, permissions); + } + + /** + * Bulk create/edit guild slash commands + * @arg {Array} commands An array of [Command objects](https://discord.com/developers/docs/interactions/slash-commands#application-command-object) + * @returns {Promise} Resolves with a commands object + */ + bulkEditCommands(commands) { + return this._client.createGuildCommands.call(this._client, this.id, commands); + } + /** * Create a channel in the guild * @arg {String} name The name of the channel @@ -358,6 +377,20 @@ class Guild extends Base { return this._client.createChannel.call(this._client, this.id, name, type, reason, options); } + /** + * Create a guild slash command + * @arg {Object} command A command object + * @arg {String} command.name The command name + * @arg {String} command.description The command description + * @arg {Array} [command.options] An array of [command options](https://discord.com/developers/docs/interactions/slash-commands#application-command-object-application-command-option-structure) + * @arg {Number} [type] CURRENTLY IN PRIVATE BETA The type of slash command, 1 for slash command, 2 for user and 3 for message (1 by default) + * @arg {Boolean} [command.defaultPermission] Whether the command is enabled by default when the app is added to a guild + * @returns {Promise} Resolves with a command object + */ + createCommand(command) { + return this._client.createGuildCommand.call(this._client, this.id, command); + } + /** * Create a emoji in the guild * @arg {Object} options Emoji options @@ -404,6 +437,15 @@ class Guild extends Base { return this._client.deleteGuild.call(this._client, this.id); } + /** + * Delete a guild slash command + * @arg {String} commandID The command id + * @returns {Promise} Resolves with a promise object + */ + deleteCommand(commandID) { + return this._client.deleteGuildCommand.call(this._client, this.id, commandID); + } + /** * Delete a discovery subcategory * @arg {String} categoryID The ID of the discovery category @@ -517,6 +559,31 @@ class Guild extends Base { return this._client.editGuild.call(this._client, this.id, options, reason); } + /** + * Edit a guild slash command + * @arg {String} commandID The command id + * @arg {Object} command A command object + * @arg {String} command.name The command name + * @arg {String} command.description The command description + * @arg {Array} [command.options] An array of [command options](https://discord.com/developers/docs/interactions/slash-commands#application-command-object-application-command-option-structure) + * @arg {Boolean} [command.defaultPermission] Whether the command is enabled by default when the app is added to a guild + * @returns {Promise} Resolves with a command object + */ + editCommand(commandID, commands) { + return this._client.editGuildCommand.call(this._client, this.id, commandID, commands); + } + + /** + * Edits command permissions for a specific command in a guild. + * Note: You can only add up to 10 permission overwrites for a command. + * @arg {String} commandID The command id + * @arg {Array} permissions An array of [permissions objects](https://discord.com/developers/docs/interactions/slash-commands#application-command-permissions-object-application-command-permissions-structure) + * @returns {Promise} Resolves with a [GuildApplicationCommandPermissions](https://discord.com/developers/docs/interactions/slash-commands#application-command-permissions-object-guild-application-command-permissions-structure) object. + */ + editCommandPermissions(commandID, permissions) { + return this._client.getCommandPermissions.call(this._client, this.id, commandID, permissions); + } + /** * Edit the guild's discovery data * @arg {Object} [options] The guild discovery data @@ -723,6 +790,31 @@ class Guild extends Base { return this._client.getGuildBans.call(this._client, this.id); } + /** + * Get a guild slash command + * @arg {String} commandID The command id + * @returns {Promise} Resolves with a command object + */ + getCommand(commandID) { + return this._client.getGuildCommand.call(this._client, this.id, commandID); + } + + /** + * Get the a guild's slash command permissions + * @arg {String} commandID The command id + * @returns {Promise} Resolves with a guild application command permissions object. + */ + getCommandPermissions(commandID) { + return this._client.getCommandPermissions.call(this._client, this.id, commandID); + } + + /** + * Get the guild's slash commands + * @returns {Promise>} Resolves with an array of command objects + */ + getCommands() { + return this._client.getGuildCommands.call(this._client, this.id); + } /** * Get the guild's discovery object @@ -732,6 +824,14 @@ class Guild extends Base { return this._client.getGuildDiscovery.call(this._client, this.id); } + /** + * Get the all of a guild's slash command permissions + * @returns {Promise>} Resolves with an array of guild application command permissions objects. + */ + getGuildCommandPermissions() { + return this._client.getGuildCommandPermissions.call(this._client, this.id); + } + /** * Get a list of integrations for the guild * @returns {Promise}