diff --git a/packages/builders/__tests__/interactions/ContextMenuCommands.test.ts b/packages/builders/__tests__/interactions/ContextMenuCommands.test.ts index 16047ce7e..baf866a1d 100644 --- a/packages/builders/__tests__/interactions/ContextMenuCommands.test.ts +++ b/packages/builders/__tests__/interactions/ContextMenuCommands.test.ts @@ -1,3 +1,4 @@ +import { PermissionFlagsBits } from 'discord-api-types/v10'; import { ContextMenuCommandAssertions, ContextMenuCommandBuilder } from '../../src/index'; const getBuilder = () => new ContextMenuCommandBuilder(); @@ -116,5 +117,27 @@ describe('Context Menu Commands', () => { }); }); }); + + describe('permissions', () => { + test('GIVEN valid permission string THEN does not throw error', () => { + expect(() => getBuilder().setDefaultMemberPermissions('1')).not.toThrowError(); + }); + + test('GIVEN valid permission bitfield THEN does not throw error', () => { + expect(() => + getBuilder().setDefaultMemberPermissions(PermissionFlagsBits.AddReactions | PermissionFlagsBits.AttachFiles), + ).not.toThrowError(); + }); + + test('GIVEN null permissions THEN does not throw error', () => { + expect(() => getBuilder().setDefaultMemberPermissions(null)).not.toThrowError(); + }); + + test('GIVEN invalid inputs THEN does throw error', () => { + expect(() => getBuilder().setDefaultMemberPermissions('1.1')).toThrowError(); + + expect(() => getBuilder().setDefaultMemberPermissions(1.1)).toThrowError(); + }); + }); }); }); diff --git a/packages/builders/__tests__/interactions/SlashCommands/SlashCommands.test.ts b/packages/builders/__tests__/interactions/SlashCommands/SlashCommands.test.ts index 380be58ed..843c6262c 100644 --- a/packages/builders/__tests__/interactions/SlashCommands/SlashCommands.test.ts +++ b/packages/builders/__tests__/interactions/SlashCommands/SlashCommands.test.ts @@ -1,4 +1,4 @@ -import { APIApplicationCommandOptionChoice, ChannelType } from 'discord-api-types/v10'; +import { APIApplicationCommandOptionChoice, ChannelType, PermissionFlagsBits } from 'discord-api-types/v10'; import { SlashCommandAssertions, SlashCommandBooleanOption, @@ -476,5 +476,27 @@ describe('Slash Commands', () => { }); }); }); + + describe('permissions', () => { + test('GIVEN valid permission string THEN does not throw error', () => { + expect(() => getBuilder().setDefaultMemberPermissions('1')).not.toThrowError(); + }); + + test('GIVEN valid permission bitfield THEN does not throw error', () => { + expect(() => + getBuilder().setDefaultMemberPermissions(PermissionFlagsBits.AddReactions | PermissionFlagsBits.AttachFiles), + ).not.toThrowError(); + }); + + test('GIVEN null permissions THEN does not throw error', () => { + expect(() => getBuilder().setDefaultMemberPermissions(null)).not.toThrowError(); + }); + + test('GIVEN invalid inputs THEN does throw error', () => { + expect(() => getBuilder().setDefaultMemberPermissions('1.1')).toThrowError(); + + expect(() => getBuilder().setDefaultMemberPermissions(1.1)).toThrowError(); + }); + }); }); }); diff --git a/packages/builders/src/interactions/contextMenuCommands/ContextMenuCommandBuilder.ts b/packages/builders/src/interactions/contextMenuCommands/ContextMenuCommandBuilder.ts index d07c014e6..47d6d3ef2 100644 --- a/packages/builders/src/interactions/contextMenuCommands/ContextMenuCommandBuilder.ts +++ b/packages/builders/src/interactions/contextMenuCommands/ContextMenuCommandBuilder.ts @@ -106,7 +106,7 @@ export class ContextMenuCommandBuilder { * * @see https://discord.com/developers/docs/interactions/application-commands#permissions */ - public setDefaultMemberPermissions(permissions: Permissions | null | undefined) { + public setDefaultMemberPermissions(permissions: Permissions | bigint | number | null | undefined) { // Assert the value and parse it const permissionValue = validateDefaultMemberPermissions(permissions); diff --git a/packages/builders/src/interactions/slashCommands/SlashCommandBuilder.ts b/packages/builders/src/interactions/slashCommands/SlashCommandBuilder.ts index 6343b0b7d..6ea2e574f 100644 --- a/packages/builders/src/interactions/slashCommands/SlashCommandBuilder.ts +++ b/packages/builders/src/interactions/slashCommands/SlashCommandBuilder.ts @@ -1,6 +1,7 @@ import type { APIApplicationCommandOption, LocalizationMap, + Permissions, RESTPostAPIApplicationCommandsJSONBody, } from 'discord-api-types/v10'; import { mix } from 'ts-mixer'; @@ -108,7 +109,7 @@ export class SlashCommandBuilder { * * @see https://discord.com/developers/docs/interactions/application-commands#permissions */ - public setDefaultMemberPermissions(permissions: Permissions | null | undefined) { + public setDefaultMemberPermissions(permissions: Permissions | bigint | number | null | undefined) { // Assert the value and parse it const permissionValue = validateDefaultMemberPermissions(permissions);