Skip to content

Commit

Permalink
Update handling-permissions.mdx
Browse files Browse the repository at this point in the history
Change permission 'BanMembers' to PermissionFlagBits.BanMembers
  • Loading branch information
nicklvh authored Nov 4, 2023
1 parent 89688cf commit fff8f11
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions docs/Guide/preconditions/handling-permissions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,44 @@ people, so we can restrict usage using the [`requiredUserPermissions`][requiredu

```typescript ts2esm2cjs|{7}|{7}
import { Command } from '@sapphire/framework';
import { PermissionFlagsBits } from 'discord.js';

export class BanCommand extends Command {
public constructor(context: Command.Context) {
super(context, {
// ...
requiredUserPermissions: ['BanMembers']
requiredUserPermissions: [PermissionFlagsBits.BanMembers]
});
}
}
```

Users without the `BanMembers` permission will now be unable to use the command!
Users without the "Ban Members" permission will now be unable to use the command!

## Handling Client Permissions

It's also a good idea to verify the inverse: does the _bot_ have the `BanMembers` permission? We can use the
It's also a good idea to verify the inverse: does the _bot_ have the "Ban Members" permission? We can use the
[`requiredClientPermissions`][requiredclientpermissions] option the same way to prevent the command from being used if
not.

<!-- TODO: info block redirecting to subcommands ts guide for using corresponding decorators -->

```typescript ts2esm2cjs|{8}|{8}
import { Command } from '@sapphire/framework';
import { PermissionFlagsBits } from 'discord.js';

export class BanCommand extends Command {
public constructor(context: Command.Context) {
super(context, {
// ...
requiredUserPermissions: ['BanMembers'],
requiredClientPermissions: ['BanMembers']
requiredUserPermissions: [PermissionFlagsBits.BanMembers],
requiredClientPermissions: [PermissionFlagsBits.BanMembers]
});
}
}
```

With these changes, `BanCommand` now requires the command executor _and_ the client to have the `BanMembers` permission
With these changes, `BanCommand` now requires the command executor _and_ the client to have the "Ban Members" permission
to execute!

:::tip
Expand Down

0 comments on commit fff8f11

Please sign in to comment.