[−][src]Struct serenity::framework::standard::CreateCommand
Methods
impl CreateCommand
[src]
impl CreateCommand
pub fn batch_known_as<T: ToString, It: IntoIterator<Item = T>>(
self,
names: It
) -> Self
[src]
pub fn batch_known_as<T: ToString, It: IntoIterator<Item = T>>(
self,
names: It
) -> Self
Adds multiple aliases.
pub fn bucket(self, bucket: &str) -> Self
[src]
pub fn bucket(self, bucket: &str) -> Self
Adds a ratelimit bucket.
pub fn check<F>(self, check: F) -> Self where
F: Fn(&mut Context, &Message, &mut Args, &CommandOptions) -> bool + Send + Sync + 'static,
[src]
pub fn check<F>(self, check: F) -> Self where
F: Fn(&mut Context, &Message, &mut Args, &CommandOptions) -> bool + Send + Sync + 'static,
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 }
pub fn desc(self, desc: &str) -> Self
[src]
pub fn desc(self, desc: &str) -> Self
Description, used by other commands.
pub fn dm_only(self, dm_only: bool) -> Self
[src]
pub fn dm_only(self, dm_only: bool) -> Self
Whether command can be used only privately or not.
pub fn example(self, example: &str) -> Self
[src]
pub fn example(self, example: &str) -> Self
Example arguments, used by other commands.
pub fn exec(
self,
func: fn(_: &mut Context, _: &Message, _: Args) -> Result<(), CommandError>
) -> Self
[src]
pub fn exec(
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.
pub fn cmd<C: Command + 'static>(self, c: C) -> Self
[src]
pub fn cmd<C: Command + 'static>(self, c: C) -> Self
Like exec
but accepts a Command
directly.
pub fn cmd_with_options<C: Command + 'static>(self, c: C) -> Self
[src]
pub fn cmd_with_options<C: Command + 'static>(self, c: C) -> Self
Like cmd
but says to the builder to use this command's options instead of its own.
pub fn guild_only(self, guild_only: bool) -> Self
[src]
pub fn guild_only(self, guild_only: bool) -> Self
Whether command can be used only in guilds or not.
pub fn owner_privileges(self, owner_privileges: bool) -> Self
[src]
pub fn owner_privileges(self, owner_privileges: bool) -> Self
Whether owners shall bypass buckets, missing permissions, wrong channels, missing roles, and checks.
pub fn help_available(self, help_available: bool) -> Self
[src]
pub fn help_available(self, help_available: bool) -> Self
Whether command should be displayed in help list or not, used by other commands.
pub fn known_as(self, name: &str) -> Self
[src]
pub fn known_as(self, name: &str) -> Self
Adds an alias, allowing users to use the command under a different name.
pub fn max_args(self, max_args: i32) -> Self
[src]
pub fn max_args(self, max_args: i32) -> Self
Maximum amount of arguments that can be passed.
pub fn min_args(self, min_args: i32) -> Self
[src]
pub fn min_args(self, min_args: i32) -> Self
Minimum amount of arguments that should be passed.
pub fn num_args(self, num_args: i32) -> Self
[src]
pub fn num_args(self, num_args: i32) -> Self
Exact number of arguments that should be passed.
pub fn owners_only(self, owners_only: bool) -> Self
[src]
pub fn owners_only(self, owners_only: bool) -> Self
Whether command can be used only privately or not.
pub fn required_permissions(self, permissions: Permissions) -> Self
[src]
pub fn required_permissions(self, permissions: Permissions) -> Self
The permissions that a user must have in the contextual channel in order for the command to be processed.
pub fn usage(self, usage: &str) -> Self
[src]
pub fn usage(self, usage: &str) -> Self
Command usage schema, used by other commands.
pub fn allowed_roles<T: ToString, It: IntoIterator<Item = T>>(
self,
allowed_roles: It
) -> Self
[src]
pub fn allowed_roles<T: ToString, It: IntoIterator<Item = T>>(
self,
allowed_roles: It
) -> Self
Sets roles that are allowed to use the command.
pub fn init<F: Fn() + Send + Sync + 'static>(self, f: F) -> Self
[src]
pub fn init<F: Fn() + Send + Sync + 'static>(self, f: F) -> Self
Sets an initialise middleware to be called upon the command's actual registration.
This is similar to implementing the init
function on Command
.
pub fn before<F: Send + Sync + 'static>(self, f: F) -> Self where
F: Fn(&mut Context, &Message) -> bool,
[src]
pub fn before<F: Send + Sync + 'static>(self, f: F) -> Self where
F: Fn(&mut Context, &Message) -> bool,
Sets a before middleware to be called before the command's execution.
This is similar to implementing the before
function on Command
.
pub fn after<F: Send + Sync + 'static>(self, f: F) -> Self where
F: Fn(&mut Context, &Message, &Result<(), CommandError>),
[src]
pub fn after<F: Send + Sync + 'static>(self, f: F) -> Self where
F: Fn(&mut Context, &Message, &Result<(), CommandError>),
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]
impl Default for CreateCommand
fn default() -> CreateCommand
[src]
fn default() -> CreateCommand
Returns the "default value" for a type. Read more
Auto Trait Implementations
impl Send for CreateCommand
impl Send for CreateCommand
impl Sync for CreateCommand
impl Sync for CreateCommand
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 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> Erased for T
impl<T> Typeable for T where
T: Any,
impl<T> Typeable for T where
T: Any,
impl<T> UnsafeAny for T where
T: Any,
impl<T> UnsafeAny for T where
T: Any,