Skip to content

Commit

Permalink
Add most client slash command functions
Browse files Browse the repository at this point in the history
Still missing all Permissions related ones
  • Loading branch information
JustCat80 committed Jul 4, 2021
1 parent d968eb0 commit 0b0ca56
Showing 1 changed file with 202 additions and 0 deletions.
202 changes: 202 additions & 0 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,49 @@ class Client extends EventEmitter {
return this.requestHandler.request("POST", Endpoints.CHANNEL_WEBHOOKS(channelID), true, options);
}

/**
* Create a global slash command
* @arg {Object} command Command object
* @arg {String} command.name The command name
* @arg {String} command.description The command description
* @arg {String} [command.options] The parameters for the command
* @arg {Boolean} [defaultPermission] Whether the command is enabled by default when the app is added to a guild
* @returns {Promise<Object>} Resolves with a webhook 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);
}

/**
* Bulk create global slash commands
* @arg {Array} commands Command object
* @arg {Object} commands.command Command object
* @arg {String} commands.command.name The command name
* @arg {String} commands.command.description The command description
* @arg {String} [commands.command.options] The parameters for the command
* @arg {Boolean} [commands.defaultPermission] Whether the command is enabled by default when the app is added to a guild
* @returns {Promise<Object>} Resolves with a webhook object
*/
createCommands(commands) {
for(const command in 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);
}

/**
* [USER ACCOUNT] Create a group channel with other users
* @arg {Array<String>} userIDs The IDs of the other users
Expand Down Expand Up @@ -526,6 +569,52 @@ 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 Command object
* @arg {String} command.name The command name
* @arg {String} command.description The command description
* @arg {String} [command.options] The parameters for the command
* @arg {Boolean} [defaultPermission] Whether the command is enabled by default when the app is added to a guild
* @returns {Promise<Object>} Resolves with a webhook 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);
}

/**
* Bulk create guild slash commands
* @arg {String} guildID Guild id to create the commands in
* @arg {Array} commands Command object
* @arg {Object} commands.command Command object
* @arg {String} commands.command.name The command name
* @arg {String} commands.command.description The command description
* @arg {String} [commands.command.options] The parameters for the command
* @arg {Boolean} [commands.defaultPermission] Whether the command is enabled by default when the app is added to a guild
* @returns {Promise<Object>} Resolves with a webhook object
*/
createGuildCommands(guildID, commands) {
for(const command in 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);
}


/**
* Create a guild emoji object
* @arg {String} guildID The ID of the guild to create the emoji in
Expand Down Expand Up @@ -698,6 +787,18 @@ class Client extends EventEmitter {
});
}

/**
* Delete a global slash command
* @arg {String} commandID The command id
* @returns {Promise} Resolves with a webhook object
*/
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
Expand All @@ -707,6 +808,22 @@ class Client extends EventEmitter {
return this.requestHandler.request("DELETE", Endpoints.GUILD(guildID), true);
}

/**
* Delete a global slash command
* @arg {String} guildID The guild id
* @arg {String} commandID The command id
* @returns {Promise} Resolves with a webhook object
*/
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
Expand Down Expand Up @@ -1005,6 +1122,27 @@ class Client extends EventEmitter {
})));
}

/**
* Edit a global slash command
* @arg {String} commandID The command id
* @arg {Object} command Command object
* @arg {String} [command.name] The command name
* @arg {String} [command.description] The command description
* @arg {String} [command.options] The parameters for the command
* @arg {Boolean} [defaultPermission] Whether the command is enabled by default when the app is added to a guild
* @returns {Promise<Object>} Resolves with a webhook 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);
}

/**
* Edit a guild
* @arg {String} guildID The ID of the guild
Expand Down Expand Up @@ -1056,6 +1194,28 @@ class Client extends EventEmitter {
}).then((guild) => new Guild(guild, this));
}

/**
* Edit a guild slash command
* @arg {String} guildID The guild id
* @arg {String} commandID The command id
* @arg {Object} command Command object
* @arg {String} [command.name] The command name
* @arg {String} [command.description] The command description
* @arg {String} [command.options] The parameters for the command
* @arg {Boolean} [defaultPermission] Whether the command is enabled by default when the app is added to a guild
* @returns {Promise<Object>} Resolves with a webhook 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
Expand Down Expand Up @@ -1606,6 +1766,26 @@ 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 a webhook 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 global slash commands
* @returns {Promise} Resolves with a webhook object
*/
getCommands() {
return this.requestHandler.request("GET", Endpoints.COMMANDS(this.application.id), true);
}

/**
* Get a list of discovery categories
* @returns {Promise<Array<Object>>}
Expand Down Expand Up @@ -1731,6 +1911,28 @@ class Client extends EventEmitter {
});
}

/**
* Get a global slash command
* @arg {String} guildID The guild id
* @arg {String} commandID The command id
* @returns {Promise} Resolves with a webhook 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 global slash commands
* @arg {String} guildID The guild id
* @returns {Promise} Resolves with a webhook object
*/
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
Expand Down

0 comments on commit 0b0ca56

Please sign in to comment.