Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Nov 9, 2022
1 parent ff85481 commit a664545
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,7 @@ const memberPermissionPredicate = s.union(
export function validateDefaultMemberPermissions(permissions: unknown) {
return memberPermissionPredicate.parse(permissions);
}

export function validateNSFW(value: unknown): asserts value is boolean {
booleanPredicate.parse(value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
validateDMPermission,
validateMaxOptionsLength,
validateRequiredParameters,
validateNSFW,
} from './Assertions.js';
import { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from './SlashCommandSubcommands.js';
import { SharedNameAndDescription } from './mixins/NameAndDescription.js';
Expand Down Expand Up @@ -64,6 +65,11 @@ export class SlashCommandBuilder {
*/
public readonly dm_permission: boolean | undefined = undefined;

/**
* Whether this command is NSFW
*/
public readonly nsfw: boolean | undefined = undefined;

/**
* Returns the final data that should be sent to Discord.
*
Expand Down Expand Up @@ -134,6 +140,18 @@ export class SlashCommandBuilder {
return this;
}

/**
* Sets whether this command is NSFW
*
* @param nsfw - Whether this command is NSFW
*/
public setNSFW(nsfw = true) {
// Assert the value matches the conditions
validateNSFW(nsfw);
Reflect.set(this, 'nsfw', nsfw);
return this;
}

/**
* Adds a new subcommand group to this command
*
Expand Down
11 changes: 11 additions & 0 deletions packages/discord.js/src/structures/ApplicationCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ class ApplicationCommand extends Base {
*/
this.version = data.version;
}

if ('nsfw' in data) {
/**
* Whether this command is NSFW
* @type {?boolean}
*/
this.nsfw = data.nsfw;
} else {
this.nsfw ??= null;
}
}

/**
Expand Down Expand Up @@ -377,6 +387,7 @@ class ApplicationCommand extends Base {
('description' in command && command.description !== this.description) ||
('version' in command && command.version !== this.version) ||
(command.type && command.type !== this.type) ||
('nsfw' in command && command.nsfw !== this.nsfw) ||
// Future proof for options being nullable
// TODO: remove ?? 0 on each when nullable
(command.options?.length ?? 0) !== (this.options?.length ?? 0) ||
Expand Down
1 change: 1 addition & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ export class ApplicationCommand<PermissionsFetchType = {}> extends Base {
>;
public type: ApplicationCommandType;
public version: Snowflake;
public nsfw: boolean | null;
public delete(): Promise<ApplicationCommand<PermissionsFetchType>>;
public edit(data: Partial<ApplicationCommandData>): Promise<ApplicationCommand<PermissionsFetchType>>;
public setName(name: string): Promise<ApplicationCommand<PermissionsFetchType>>;
Expand Down

0 comments on commit a664545

Please sign in to comment.