Slash Command and Context Menu
- Doc. comming soon
This commit is contained in:
@@ -12,14 +12,15 @@ const { ApplicationCommandTypes } = require('../util/Constants');
|
||||
* @extends {CachedManager}
|
||||
*/
|
||||
class ApplicationCommandManager extends CachedManager {
|
||||
constructor(client, iterable) {
|
||||
constructor(client, iterable, user) {
|
||||
super(client, ApplicationCommand, iterable);
|
||||
|
||||
/**
|
||||
* The manager for permissions of arbitrary commands on arbitrary guilds
|
||||
* @type {ApplicationCommandPermissionsManager}
|
||||
*/
|
||||
this.permissions = new ApplicationCommandPermissionsManager(this);
|
||||
this.permissions = new ApplicationCommandPermissionsManager(this, user);
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,7 +42,7 @@ class ApplicationCommandManager extends CachedManager {
|
||||
* @private
|
||||
*/
|
||||
commandPath({ id, guildId } = {}) {
|
||||
let path = this.client.api.applications(this.client.application.id);
|
||||
let path = this.client.api.applications(this.user.id);
|
||||
if (this.guild ?? guildId) path = path.guilds(this.guild?.id ?? guildId);
|
||||
return id ? path.commands(id) : path.commands;
|
||||
}
|
||||
@@ -114,6 +115,7 @@ class ApplicationCommandManager extends CachedManager {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async create(command, guildId) {
|
||||
if(!this.client.user.bot) throw new Error("INVALID_USER_METHOD");
|
||||
const data = await this.commandPath({ guildId }).post({
|
||||
data: this.constructor.transformCommand(command),
|
||||
});
|
||||
@@ -143,6 +145,7 @@ class ApplicationCommandManager extends CachedManager {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async set(commands, guildId) {
|
||||
if(!this.client.user.bot) throw new Error("INVALID_USER_METHOD");
|
||||
const data = await this.commandPath({ guildId }).put({
|
||||
data: commands.map(c => this.constructor.transformCommand(c)),
|
||||
});
|
||||
@@ -165,6 +168,7 @@ class ApplicationCommandManager extends CachedManager {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async edit(command, data, guildId) {
|
||||
if(!this.client.user.bot) throw new Error("INVALID_USER_METHOD");
|
||||
const id = this.resolveId(command);
|
||||
if (!id) throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable');
|
||||
|
||||
@@ -187,6 +191,7 @@ class ApplicationCommandManager extends CachedManager {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async delete(command, guildId) {
|
||||
if(!this.client.user.bot) throw new Error("INVALID_USER_METHOD");
|
||||
const id = this.resolveId(command);
|
||||
if (!id) throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable');
|
||||
|
||||
|
@@ -10,7 +10,7 @@ const { ApplicationCommandPermissionTypes, APIErrors } = require('../util/Consta
|
||||
* @extends {BaseManager}
|
||||
*/
|
||||
class ApplicationCommandPermissionsManager extends BaseManager {
|
||||
constructor(manager) {
|
||||
constructor(manager, user) {
|
||||
super(manager.client);
|
||||
|
||||
/**
|
||||
@@ -37,6 +37,8 @@ class ApplicationCommandPermissionsManager extends BaseManager {
|
||||
* @type {?Snowflake}
|
||||
*/
|
||||
this.commandId = manager.id ?? null;
|
||||
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,7 +49,7 @@ class ApplicationCommandPermissionsManager extends BaseManager {
|
||||
* @private
|
||||
*/
|
||||
permissionsPath(guildId, commandId) {
|
||||
return this.client.api.applications(this.client.application.id).guilds(guildId).commands(commandId).permissions;
|
||||
return this.client.api.applications(this.user.id).guilds(guildId).commands(commandId).permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,6 +161,7 @@ class ApplicationCommandPermissionsManager extends BaseManager {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async set({ guild, command, permissions, fullPermissions } = {}) {
|
||||
if(!this.manager.client.user.bot) throw new Error("INVALID_USER_METHOD");
|
||||
const { guildId, commandId } = this._validateOptions(guild, command);
|
||||
|
||||
if (commandId) {
|
||||
@@ -220,6 +223,7 @@ class ApplicationCommandPermissionsManager extends BaseManager {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async add({ guild, command, permissions }) {
|
||||
if(!this.manager.client.user.bot) throw new Error("INVALID_USER_METHOD");
|
||||
const { guildId, commandId } = this._validateOptions(guild, command);
|
||||
if (!commandId) throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable');
|
||||
if (!Array.isArray(permissions)) {
|
||||
@@ -271,6 +275,7 @@ class ApplicationCommandPermissionsManager extends BaseManager {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async remove({ guild, command, users, roles }) {
|
||||
if(!this.manager.client.user.bot) throw new Error("INVALID_USER_METHOD");
|
||||
const { guildId, commandId } = this._validateOptions(guild, command);
|
||||
if (!commandId) throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable');
|
||||
|
||||
|
Reference in New Issue
Block a user