feat: partially backport perms v2 for v13
v13.9.0 :yay: https://github.com/discordjs/discord.js/pull/8162
This commit is contained in:
@@ -6,6 +6,7 @@ const CachedManager = require('./CachedManager');
|
||||
const { TypeError } = require('../errors');
|
||||
const ApplicationCommand = require('../structures/ApplicationCommand');
|
||||
const { ApplicationCommandTypes } = require('../util/Constants');
|
||||
const Permissions = require('../util/Permissions');
|
||||
|
||||
/**
|
||||
* Manages API methods for application commands and stores their cache.
|
||||
@@ -167,7 +168,7 @@ class ApplicationCommandManager extends CachedManager {
|
||||
/**
|
||||
* Edits an application command.
|
||||
* @param {ApplicationCommandResolvable} command The command to edit
|
||||
* @param {ApplicationCommandData|APIApplicationCommand} data The data to update the command with
|
||||
* @param {Partial<ApplicationCommandData|APIApplicationCommand>} data The data to update the command with
|
||||
* @param {Snowflake} [guildId] The guild's id where the command registered,
|
||||
* ignored when using a {@link GuildApplicationCommandManager}
|
||||
* @returns {Promise<ApplicationCommand>}
|
||||
@@ -221,6 +222,19 @@ class ApplicationCommandManager extends CachedManager {
|
||||
* @private
|
||||
*/
|
||||
static transformCommand(command) {
|
||||
let default_member_permissions;
|
||||
|
||||
if ('default_member_permissions' in command) {
|
||||
default_member_permissions = command.default_member_permissions
|
||||
? new Permissions(BigInt(command.default_member_permissions)).bitfield.toString()
|
||||
: command.default_member_permissions;
|
||||
}
|
||||
|
||||
if ('defaultMemberPermissions' in command) {
|
||||
default_member_permissions = command.defaultMemberPermissions
|
||||
? new Permissions(command.defaultMemberPermissions).bitfield.toString()
|
||||
: command.defaultMemberPermissions;
|
||||
}
|
||||
return {
|
||||
name: command.name,
|
||||
name_localizations: command.nameLocalizations ?? command.name_localizations,
|
||||
@@ -229,6 +243,8 @@ class ApplicationCommandManager extends CachedManager {
|
||||
type: typeof command.type === 'number' ? command.type : ApplicationCommandTypes[command.type],
|
||||
options: command.options?.map(o => ApplicationCommand.transformOption(o)),
|
||||
default_permission: command.defaultPermission ?? command.default_permission,
|
||||
default_member_permissions,
|
||||
dm_permission: command.dmPermission ?? command.dm_permission,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user