Skip to content
GitHub

permissionNames

function in meocord/common Since 4.3.0

permissionNames(
  permissions: PermissionResolvable,
  target: PermissionTarget | undefined,
  options: PermissionNamesOptions & { join: keyof typeof JOINS },
): string

permissionNames(
  permissions: PermissionResolvable,
  target?: PermissionTarget,
  options?: PermissionNamesOptions & { join?: undefined },
): string[]

The permissions as a server owner reads them in Discord's role settings, such as Ban Members for BanMembers, in the language of the user or server they are for.

Use it to say which permission a guard or a bot lacks. Labels come in bit order, one per bit: a bit with two flag names, as 1 << 30 has, gives one. A bit with no label gives its flag name, and a bit discord.js has no name for gives Unknown permission (1 << n), so none is left out.

An interaction's labels are in its user's locale and a message's in its server's, through its app's translator; a Locale names the language, with options.t as the translator. Without a translator or a target they are MeoCord's English. The labels are MeoCord's texts in meocord.permissions, by flag name, which an app's catalog translates.

Some of Discord's labels hold commas, such as Kick, Approve, and Reject Members, and join lists them as they are: KickMembers and BanMembers read Kick, Approve, and Reject Members and Ban Members.

Parameters

NameType
permissionsPermissionResolvable

What discord.js reads as permissions: a PermissionsBitField, a bigint, a flag name or an array.

targetPermissionTarget | undefined

The interaction or message the labels are for, or a locale.

optionsPermissionNamesOptions & { join: keyof typeof JOINS }

join, which joins the labels into one string, and the translator.

options.join'and' | 'or'

Joins the labels into one sentence part with the language's and or or, such as "A, B, and C".

options.t?Translator<any>

The translator, for a Locale target or to use another than the target's app's.

Returns

string

The labels joined as a list in their language.

Throws

  • RangeError when permissions names a flag discord.js doesn't know, as discord.js throws.

Examples

TypeScript
declare const interaction: ChatInputCommandInteraction

const missing = interaction.memberPermissions?.missing([PermissionFlagsBits.ManageMessages, PermissionFlagsBits.BanMembers]) ?? []
if (missing.length > 0) throw new GuardDeniedError(`You need ${permissionNames(missing, interaction, { join: 'and' })}.`)
// 'You need Ban Members and Manage Messages.'

Parameters

NameType
permissionsPermissionResolvable

What discord.js reads as permissions: a PermissionsBitField, a bigint, a flag name or an array.

target?PermissionTarget

The interaction or message the labels are for, or a locale.

options?PermissionNamesOptions & { join?: undefined }

The translator.

options.join?undefined

Joins the labels into one sentence part with the language's and or or, such as "A, B, and C".

options.t?Translator<any>

The translator, for a Locale target or to use another than the target's app's.

Returns

string[]

A label per bit.

Throws

  • RangeError when permissions names a flag discord.js doesn't know, as discord.js throws.

Examples

TypeScript
permissionNames(['ManageMessages', 'BanMembers']) // ['Ban Members', 'Manage Messages']