Struct serenity::framework::standard::CreateCommand [] [src]

pub struct CreateCommand(pub Command);

Methods

impl CreateCommand
[src]

[src]

Adds multiple aliases.

[src]

Adds a ratelimit bucket.

[src]

Adds a "check" to a command, which checks whether or not the command's function should be called.

Examples

Ensure that the user who created a message, calling a "ping" command, is the owner.

use serenity::client::{Client, Context};
use serenity::framework::standard::{
    Args,
    Command,
    CommandError,
    StandardFramework,
};
use serenity::model::Message;
use std::env;
use std::sync::Arc;

let mut client = Client::new(&env::var("DISCORD_TOKEN").unwrap(), Handler);

client.with_framework(StandardFramework::new()
    .configure(|c| c.prefix("~"))
    .command("ping", |c| c
        .check(owner_check)
        .desc("Replies to a ping with a pong")
        .exec(ping)));

fn ping(_context: &mut Context, message: &Message, _args: Args) -> Result<(),
CommandError> {
    message.channel_id.say("Pong!")?;

    Ok(())
}

fn owner_check(_context: &mut Context, message: &Message, _: &mut Args, _:
&Arc<Command>) -> bool {
    // replace with your user ID
    message.author.id == 7
}

[src]

Description, used by other commands.

[src]

Whether command can be used only privately or not.

[src]

Example arguments, used by other commands.

[src]

A function that can be called when a command is received. You can return Err(string) if there's an error.

See exec_str if you only need to return a string on command use.

[src]

Sets a function that's called when a command is called that can access the internal HashMap of commands, used specifically for creating a help command.

You can return Err(From::from(string)) if there's an error.

[src]

Sets a string to be sent in the channel of context on command. This can be useful for an about, invite, ping, etc. command.

Examples

Create a command named "ping" that returns "Pong!":

client.with_framework(|f| f
    .command("ping", |c| c.exec_str("Pong!")));

[src]

Whether command can be used only in guilds or not.

[src]

Whether command should be displayed in help list or not, used by other commands.

[src]

Adds an alias, allowing users to use the command under a different name.

[src]

Maximum amount of arguments that can be passed.

[src]

Minumum amount of arguments that should be passed.

[src]

Exact number of arguments that should be passed.

[src]

Whether command can be used only privately or not.

[src]

The permissions that a user must have in the contextual channel in order for the command to be processed.

[src]

Command usage schema, used by other commands.

[src]

Sets roles that are allowed to use the command.