mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 02:23:31 +01:00
feat(builders): add new command permissions v2 (#7861)
This commit is contained in:
@@ -6,8 +6,10 @@ import type {
|
||||
import { mix } from 'ts-mixer';
|
||||
import {
|
||||
assertReturnOfBuilder,
|
||||
validateDefaultMemberPermissions,
|
||||
validateDefaultPermission,
|
||||
validateLocalizationMap,
|
||||
validateDMPermission,
|
||||
validateMaxOptionsLength,
|
||||
validateRequiredParameters,
|
||||
} from './Assertions';
|
||||
@@ -45,9 +47,21 @@ export class SlashCommandBuilder {
|
||||
/**
|
||||
* Whether the command is enabled by default when the app is added to a guild
|
||||
*
|
||||
* @default true
|
||||
* @deprecated This property is deprecated and will be removed in the future.
|
||||
* You should use `setDefaultMemberPermissions` or `setDMPermission` instead.
|
||||
*/
|
||||
public readonly defaultPermission: boolean | undefined = undefined;
|
||||
public readonly default_permission: boolean | undefined = undefined;
|
||||
|
||||
/**
|
||||
* Set of permissions represented as a bit set for the command
|
||||
*/
|
||||
public readonly default_member_permissions: Permissions | null | undefined = undefined;
|
||||
|
||||
/**
|
||||
* Indicates whether the command is available in DMs with the application, only for globally-scoped commands.
|
||||
* By default, commands are visible.
|
||||
*/
|
||||
public readonly dm_permission: boolean | null | undefined = undefined;
|
||||
|
||||
/**
|
||||
* Returns the final data that should be sent to Discord.
|
||||
@@ -61,12 +75,8 @@ export class SlashCommandBuilder {
|
||||
validateLocalizationMap(this.description_localizations);
|
||||
|
||||
return {
|
||||
name: this.name,
|
||||
name_localizations: this.name_localizations,
|
||||
description: this.description,
|
||||
description_localizations: this.description_localizations,
|
||||
...this,
|
||||
options: this.options.map((option) => option.toJSON()),
|
||||
default_permission: this.defaultPermission,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -78,12 +88,48 @@ export class SlashCommandBuilder {
|
||||
* @param value Whether or not to enable this command by default
|
||||
*
|
||||
* @see https://discord.com/developers/docs/interactions/application-commands#permissions
|
||||
* @deprecated Use `setDefaultMemberPermissions` or `setDMPermission` instead.
|
||||
*/
|
||||
public setDefaultPermission(value: boolean) {
|
||||
// Assert the value matches the conditions
|
||||
validateDefaultPermission(value);
|
||||
|
||||
Reflect.set(this, 'defaultPermission', value);
|
||||
Reflect.set(this, 'default_permission', value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default permissions a member should have in order to run the command.
|
||||
*
|
||||
* **Note:** You can set this to `'0'` to disable the command by default.
|
||||
*
|
||||
* @param permissions The permissions bit field to set
|
||||
*
|
||||
* @see https://discord.com/developers/docs/interactions/application-commands#permissions
|
||||
*/
|
||||
public setDefaultMemberPermissions(permissions: Permissions | null | undefined) {
|
||||
// Assert the value and parse it
|
||||
const permissionValue = validateDefaultMemberPermissions(permissions);
|
||||
|
||||
Reflect.set(this, 'default_member_permissions', permissionValue);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if the command is available in DMs with the application, only for globally-scoped commands.
|
||||
* By default, commands are visible.
|
||||
*
|
||||
* @param enabled If the command should be enabled in DMs
|
||||
*
|
||||
* @see https://discord.com/developers/docs/interactions/application-commands#permissions
|
||||
*/
|
||||
public setDMPermission(enabled: boolean | null | undefined) {
|
||||
// Assert the value matches the conditions
|
||||
validateDMPermission(enabled);
|
||||
|
||||
Reflect.set(this, 'dm_permission', enabled);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user