Skip to content

Commit

Permalink
Update handling-permissions.mdx (#243)
Browse files Browse the repository at this point in the history
* Update handling-permissions.mdx

Change BAN_MEMBERS to BanMembers

* Update handling-permissions.mdx

Change permission 'BanMembers' to PermissionFlagBits.BanMembers
  • Loading branch information
nicklvh authored Nov 4, 2023
1 parent ab3c4f3 commit 6b642aa
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: ['BAN_MEMBERS']
requiredUserPermissions: [PermissionFlagsBits.BanMembers]
});
}
}
```

Users without the `BAN_MEMBERS` 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 `BAN_MEMBERS` 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: ['BAN_MEMBERS'],
requiredClientPermissions: ['BAN_MEMBERS']
requiredUserPermissions: [PermissionFlagsBits.BanMembers],
requiredClientPermissions: [PermissionFlagsBits.BanMembers]
});
}
}
```

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

:::tip
Expand Down

1 comment on commit 6b642aa

@vercel
Copy link

@vercel vercel bot commented on 6b642aa Nov 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.