Skip to main content

Function: RequiresUserPermissions()

RequiresUserPermissions(...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 user of the command. For setting permissions required for the client see RequiresClientPermissions

Remark

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

Example

import { ApplyOptions, RequiresUserPermissions } 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)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.
public async add(message: Message) {
return message.channel.send('Adding!');
}

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

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

Source

djs-decorators.ts:152