Skip to main content

Function: RequiresClientPermissions()

RequiresClientPermissions(...permissionsResolvable: PermissionResolvable[]): MethodDecorator

Allows you to set permissions required for individual methods. This is particularly useful for subcommands that require specific permissions.

Parameters

ParameterTypeDescription
...permissionsResolvablePermissionResolvable[]Permissions that the method should have.

Returns

MethodDecorator

Remark

This decorator applies to the client that is to execute the command. For setting permissions required user of the command see RequiresUserPermissions

Remark

This decorator makes the decorated function asynchronous, so any result should be awaited.

Example

import { ApplyOptions, RequiresClientPermissions } from '@sapphire/decorators';
import { Subcommand } from '@sapphire/plugin-subcommands';
import type { Message } from 'discord.js';

(at)ApplyOptions<Subcommand.Options>({
aliases: ['cws'],
description: 'A basic command with some subcommands',
subCommands: ['add', 'remove', 'reset', { input: 'show', default: true }]
})
export default class extends Subcommand {
// Anyone should be able to view the result, but not modify
public async show(message: Message) {
return message.channel.send('Showing!');
}

(at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.
public async add(message: Message) {
return message.channel.send('Adding!');
}

(at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.
public async remove(message: Message) {
return message.channel.send('Removing!');
}

(at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.
public async reset(message: Message) {
return message.channel.send('Resetting!');
}
}

Source

djs-decorators.ts:80