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
| Name | Type |
|---|---|
permissions | PermissionResolvable |
What discord.js reads as permissions: a | |
target | PermissionTarget | undefined |
The interaction or message the labels are for, or a locale. | |
options | PermissionNamesOptions & {
join: keyof typeof JOINS
} |
| |
options.join | 'and' | 'or' |
Joins the labels into one sentence part with the language's | |
options.t? | Translator<any> |
The translator, for a | |
Returns
stringThe labels joined as a list in their language.
Throws
RangeError when
permissionsnames a flag discord.js doesn't know, as discord.js throws.
Examples
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
| Name | Type |
|---|---|
permissions | PermissionResolvable |
What discord.js reads as permissions: a | |
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 | |
options.t? | Translator<any> |
The translator, for a | |
Returns
string[]A label per bit.
Throws
RangeError when
permissionsnames a flag discord.js doesn't know, as discord.js throws.
Examples
permissionNames(['ManageMessages', 'BanMembers']) // ['Ban Members', 'Manage Messages']