Skip to content

Commit

Permalink
Undocumented #[required_permissions(perms)] requirements (#1479)
Browse files Browse the repository at this point in the history
* Fix misleading command framework example and add `#[required_permissions(perms)]` requirement docs

Co-Authored-By: Victoria Casasampere Fernandez <vickyf5124@gmail.com>
Co-Authored-By: Splingush <9380654+Splingush@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Alex M. M. <acdenissk69@gmail.com>

Co-authored-by: Victoria Casasampere Fernandez <vickyf5124@gmail.com>
Co-authored-by: Splingush <9380654+Splingush@users.noreply.github.com>
Co-authored-by: Alex M. M. <acdenissk69@gmail.com>
  • Loading branch information
4 people committed Aug 29, 2021
1 parent 2da46a8 commit f9de6c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions command_attr/src/lib.rs
Expand Up @@ -69,7 +69,7 @@ macro_rules! match_options {
/// | `#[example(ex)]` </br> `#[example = ex]` | An example of the command's usage. May be called multiple times to add many examples at once. | `ex` is a string |
/// | `#[delimiters(delims)]` | Argument delimiters specific to this command. Overrides the global list of delimiters in the framework. | `delims` is a comma separated list of strings |
/// | `#[min_args(min)]` </br> `#[max_args(max)]` </br> `#[num_args(min_and_max)]` | The expected length of arguments that the command must receive in order to function correctly. | `min`, `max` and `min_and_max` are 16-bit, unsigned integers. |
/// | `#[required_permissions(perms)]` | Set of permissions the user must possess. | `perms` is a comma separated list of permission names.</br> These can be found at [Discord's official documentation](https://discord.com/developers/docs/topics/permissions). |
/// | `#[required_permissions(perms)]` | Set of permissions the user must possess. </br> In order for this attribute to work, "Presence Intent" and "Server Member Intent" options in bot application must be enabled and all intent flags must be enabled during client creation. | `perms` is a comma separated list of permission names.</br> These can be found at [Discord's official documentation](https://discord.com/developers/docs/topics/permissions). |
/// | `#[allowed_roles(roles)]` | Set of roles the user must possess. | `roles` is a comma separated list of role names. |
/// | `#[help_available]` </br> `#[help_available(b)]` | If the command should be displayed in the help message. | `b` is a boolean. If no boolean is provided, the value is assumed to be `true`. |
/// | `#[only_in(ctx)]` | Which environment the command can be executed in. | `ctx` is a string with the accepted values `guild`/`guilds` and `dm`/`dms` (Direct Message). |
Expand Down Expand Up @@ -596,7 +596,7 @@ pub fn help(attr: TokenStream, input: TokenStream) -> TokenStream {
/// | `#[owner_privilege]` </br> `#[owner_privilege(b)]` | If owners can bypass certain options. | `b` is a boolean. If no boolean is provided, the value is assumed to be `true`. |
/// | `#[help_available]` </br> `#[help_available(b)]` | If the group should be displayed in the help message. | `b` is a boolean. If no boolean is provided, the value is assumed to be `true`. |
/// | `#[checks(identifiers)]` | Preconditions that must met before the command's execution. | `identifiers` is a comma separated list of identifiers referencing functions marked by the `#[check]` macro |
/// | `#[required_permissions(perms)]` | Set of permissions the user must possess. | `perms` is a comma separated list of permission names.</br> These can be found at [Discord's official documentation](https://discord.com/developers/docs/topics/permissions). |
/// | `#[required_permissions(perms)]` | Set of permissions the user must possess. </br> In order for this attribute to work, "Presence Intent" and "Server Member Intent" options in bot application must be enabled and all intent flags must be enabled during client creation. | `perms` is a comma separated list of permission names.</br> These can be found at [Discord's official documentation](https://discord.com/developers/docs/topics/permissions). |
/// | `#[default_command(cmd)]` | A command to execute if none of the group's prefixes are given. | `cmd` is an identifier referencing a function marked by the `#[command]` macro |
/// | `#[description(desc)]` </br> `#[description = desc]` | The group's description or summary. | `desc` is a string describing the group. |
/// | `#[summary(desc)]` </br> `#[summary = desc]` | A summary group description displayed when shown multiple groups. | `desc` is a string summaryly describing the group. |
Expand Down
9 changes: 8 additions & 1 deletion examples/e05_command_framework/src/main.rs
Expand Up @@ -18,7 +18,7 @@ use std::{
use serenity::prelude::*;
use serenity::{
async_trait,
client::bridge::gateway::{ShardId, ShardManager},
client::bridge::gateway::{ShardId, ShardManager, GatewayIntents},
framework::standard::{
buckets::{LimitedFor, RevertBucket},
help_commands,
Expand Down Expand Up @@ -307,6 +307,13 @@ async fn main() {
let mut client = Client::builder(&token)
.event_handler(Handler)
.framework(framework)
// For this example to run properly, the "Presence Intent" and "Server Members Intent"
// options need to be enabled.
// These are needed so the `required_permissions` macro works on the commands that need to
// use it.
// You will need to enable these 2 options on the bot application, and possibly wait up to 5
// minutes.
.intents(GatewayIntents::all())
.await
.expect("Err creating client");

Expand Down

0 comments on commit f9de6c5

Please sign in to comment.