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

pub struct CreateCommand(pub CommandOptions, pub FnOrCommand, pub Handlers);

Methods

impl CreateCommand
[src]

Adds multiple aliases.

Adds a ratelimit bucket.

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

Note: These checks are bypassed for commands sent by the application owner.

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,
    CommandOptions,
    CommandError,
    StandardFramework,
};
use serenity::model::channel::Message;
use std::env;

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

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, _:
&CommandOptions) -> bool {
    // replace with your user ID
    message.author.id == 7
}

Description, used by other commands.

Whether command can be used only privately or not.

Example arguments, used by other commands.

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

Like exec but accepts a Command directly.

Like cmd but says to the builder to use this command's options instead of its own.

Whether command can be used only in guilds or not.

Whether owners shall bypass buckets, missing permissions, wrong channels, missing roles, and checks.

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

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

Maximum amount of arguments that can be passed.

Minimum amount of arguments that should be passed.

Exact number of arguments that should be passed.

Whether command can be used only privately or not.

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

Command usage schema, used by other commands.

Sets roles that are allowed to use the command.

Sets an initialise middleware to be called upon the command's actual registration.

This is similar to implementing the init function on Command.

Sets a before middleware to be called before the command's execution.

This is similar to implementing the before function on Command.

Sets an after middleware to be called after the command's execution.

This is similar to implementing the after function on Command.

Trait Implementations

impl Default for CreateCommand
[src]

Returns the "default value" for a type. Read more

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

Performs the conversion.

impl<T> From for T
[src]

Performs the conversion.

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Borrow for T where
    T: ?Sized
[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut for T where
    T: ?Sized
[src]

Mutably borrows from an owned value. Read more

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

🔬 This is a nightly-only experimental API. (get_type_id)

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more

impl<T> Erased for T

impl<T> Typeable for T where
    T: Any

Get the TypeId of this object.

impl<T> UnsafeAny for T where
    T: Any