Struct serenity::framework::standard::CreateCommand
[−]
[src]
pub struct CreateCommand(pub Command);
Methods
impl CreateCommand
[src]
fn batch_known_as(self, names: Vec<&str>) -> Self
[src]
Adds multiple aliases.
fn bucket(self, bucket: &str) -> Self
[src]
Adds a ratelimit bucket.
fn check<F>(self, check: F) -> Self where
F: Fn(&mut Context, &Message, &mut Args, &Arc<Command>) -> bool + Send + Sync + 'static,
[src]
F: Fn(&mut Context, &Message, &mut Args, &Arc<Command>) -> bool + Send + Sync + 'static,
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 }
fn desc(self, desc: &str) -> Self
[src]
Description, used by other commands.
fn dm_only(self, dm_only: bool) -> Self
[src]
Whether command can be used only privately or not.
fn example(self, example: &str) -> Self
[src]
Example arguments, used by other commands.
fn exec(
self,
func: fn(_: &mut Context, _: &Message, _: Args) -> Result<(), CommandError>
) -> Self
[src]
self,
func: fn(_: &mut Context, _: &Message, _: Args) -> Result<(), CommandError>
) -> Self
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.
fn exec_help(
self,
f: fn(_: &mut Context, _: &Message, _: HashMap<String, Arc<CommandGroup>>, _: Args) -> Result<(), CommandError>
) -> Self
[src]
self,
f: fn(_: &mut Context, _: &Message, _: HashMap<String, Arc<CommandGroup>>, _: Args) -> Result<(), CommandError>
) -> Self
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.
fn exec_str(self, content: &str) -> Self
[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!")));
fn guild_only(self, guild_only: bool) -> Self
[src]
Whether command can be used only in guilds or not.
fn help_available(self, help_available: bool) -> Self
[src]
Whether command should be displayed in help list or not, used by other commands.
fn known_as(self, name: &str) -> Self
[src]
Adds an alias, allowing users to use the command under a different name.
fn max_args(self, max_args: i32) -> Self
[src]
Maximum amount of arguments that can be passed.
fn min_args(self, min_args: i32) -> Self
[src]
Minumum amount of arguments that should be passed.
fn num_args(self, num_args: i32) -> Self
[src]
Exact number of arguments that should be passed.
fn owners_only(self, owners_only: bool) -> Self
[src]
Whether command can be used only privately or not.
fn required_permissions(self, permissions: Permissions) -> Self
[src]
The permissions that a user must have in the contextual channel in order for the command to be processed.
fn usage(self, usage: &str) -> Self
[src]
Command usage schema, used by other commands.
fn allowed_roles(self, allowed_roles: Vec<&str>) -> Self
[src]
Sets roles that are allowed to use the command.