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

pub struct Configuration { /* fields omitted */ }

The configuration to use for a StandardFramework associated with a Client instance.

This allows setting configurations like the depth to search for commands, whether to treat mentions like a command prefix, etc.

To see the default values, refer to the default implementation.

Examples

Responding to mentions and setting a command prefix of "~":

struct Handler;

impl EventHandler for Handler {}

use serenity::Client;
use std::env;
use serenity::framework::StandardFramework;
use serenity::model::id::UserId;

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

client.with_framework(StandardFramework::new()
    .configure(|c| c.on_mention(Some(UserId(5))).prefix("~")));

Implementations

impl Configuration[src]

pub fn allow_dm(&mut self, allow_dm: bool) -> &mut Self[src]

If set to false, bot will ignore any private messages.

Note: Defaults to true.

pub fn with_whitespace<I: Into<WithWhiteSpace>>(&mut self, with: I) -> &mut Self[src]

Whether to allow whitespace being optional between a prefix/group-prefix/command and a command.

Note: Defaults to false (for prefixes), true (commands), true (group prefixes).

Examples

Setting false for prefixes will only allow this scenario to occur:

This example is not tested
!about

// bot processes and executes the "about" command if it exists

while setting it to true will also allow this scenario to occur:

This example is not tested
! about

// bot processes and executes the "about" command if it exists

pub fn by_space(&mut self, b: bool) -> &mut Self[src]

Whether the framework should split the message by a space first to parse the group or command. If set to false, it will only test part of the message by the length of the group's or command's names.

Note: Defaults to true

pub fn allowed_channels(&mut self, channels: HashSet<ChannelId>) -> &mut Self[src]

HashSet of channels Ids where commands will be working.

Note: Defaults to an empty HashSet.

Examples

Create a HashSet in-place:

use serenity::model::id::ChannelId;
use serenity::framework::StandardFramework;

client.with_framework(StandardFramework::new().configure(|c| c
    .allowed_channels(vec![ChannelId(7), ChannelId(77)].into_iter().collect())));

pub fn blocked_guilds(&mut self, guilds: HashSet<GuildId>) -> &mut Self[src]

HashSet of guild Ids where commands will be ignored.

Note: Defaults to an empty HashSet.

Examples

Create a HashSet in-place:

use serenity::model::id::GuildId;
use serenity::framework::StandardFramework;

client.with_framework(StandardFramework::new().configure(|c| c
    .blocked_guilds(vec![GuildId(7), GuildId(77)].into_iter().collect())));

pub fn blocked_users(&mut self, users: HashSet<UserId>) -> &mut Self[src]

HashSet of user Ids whose commands will be ignored.

Guilds owned by user Ids will also be ignored.

Note: Defaults to an empty HashSet.

Examples

Create a HashSet in-place:

use serenity::model::id::UserId;
use serenity::framework::StandardFramework;

client.with_framework(StandardFramework::new().configure(|c| c
    .blocked_users(vec![UserId(7), UserId(77)].into_iter().collect())));

pub fn disabled_commands(&mut self, commands: HashSet<String>) -> &mut Self[src]

HashSet of command names that won't be run.

Note: Defaults to an empty HashSet.

Examples

Ignore a set of commands, assuming they exist:

use serenity::framework::StandardFramework;
use serenity::client::Context;
use serenity::model::channel::Message;
use serenity::framework::standard::{CommandResult, macros::{group, command}};

#[command]
fn ping(ctx: &mut Context, msg: &Message) -> CommandResult {
    msg.channel_id.say(&ctx.http, "Pong!")?;
    Ok(())
}

#[group]
#[commands(ping)]
struct Peng;

let disabled = vec!["ping"].into_iter().map(|x| x.to_string()).collect();

client.with_framework(StandardFramework::new()
    .group(&PENG_GROUP)
    .configure(|c| c.disabled_commands(disabled)));

pub fn dynamic_prefix<F>(&mut self, dynamic_prefix: F) -> &mut Self where
    F: Fn(&mut Context, &Message) -> Option<String> + Send + Sync + 'static, 
[src]

Sets the prefix to respond to dynamically based on conditions.

Return None to not have a special prefix for the dispatch, and to instead use the inherited prefix.

Note: Defaults to no dynamic prefix check.

Examples

If the Id of the channel is divisible by 5, return a prefix of "!", otherwise return a prefix of "~".

use serenity::framework::StandardFramework;

client.with_framework(StandardFramework::new()
    .configure(|c| c.dynamic_prefix(|_, msg| {
        Some(if msg.channel_id.0 % 5 == 0 {
            "!"
        } else {
            "~"
        }.to_string())
    })));

pub fn dynamic_prefixes<F, I: IntoIterator<Item = F>>(
    &mut self,
    iter: I
) -> &mut Self where
    F: Fn(&mut Context, &Message) -> Option<String> + Send + Sync + 'static, 
[src]

pub fn ignore_bots(&mut self, ignore_bots: bool) -> &mut Self[src]

Whether the bot should respond to other bots.

For example, if this is set to false, then the bot will respond to any other bots including itself.

Note: Defaults to true.

pub fn ignore_webhooks(&mut self, ignore_webhooks: bool) -> &mut Self[src]

If set to true, bot will ignore all commands called by webhooks.

Note: Defaults to true.

pub fn on_mention(&mut self, id_to_mention: Option<UserId>) -> &mut Self[src]

Whether or not to respond to commands initiated with id_to_mention.

Note: that this can be used in conjunction with prefix.

Note: Defaults to ignore mentions.

Examples

Setting this to an ID will allow the following types of mentions to be responded to:

This example is not tested
<@245571012924538880> about
<@!245571012924538880> about

The former is a direct mention, while the latter is a nickname mention, which aids mobile devices in determining whether to display a user's nickname. It has no real meaning for your bot, and the library encourages you to ignore differentiating between the two.

pub fn owners(&mut self, user_ids: HashSet<UserId>) -> &mut Self[src]

A HashSet of user Ids checks won't apply to.

Note: Defaults to an empty HashSet.

Examples

Create a HashSet in-place:

use serenity::model::id::UserId;
use serenity::framework::StandardFramework;

client.with_framework(StandardFramework::new().configure(|c| c
    .owners(vec![UserId(7), UserId(77)].into_iter().collect())));

Create a HashSet beforehand:

use serenity::model::id::UserId;
use std::collections::HashSet;
use serenity::framework::StandardFramework;

let mut set = HashSet::new();
set.insert(UserId(7));
set.insert(UserId(77));

client.with_framework(StandardFramework::new().configure(|c| c.owners(set)));

pub fn prefix(&mut self, prefix: &str) -> &mut Self[src]

Sets the prefix to respond to. A prefix can be a string slice of any non-zero length.

Note: Defaults to an empty vector.

Examples

Assign a basic prefix:

use serenity::framework::StandardFramework;

client.with_framework(StandardFramework::new().configure(|c| c
    .prefix("!")));

pub fn prefixes<T, It>(&mut self, prefixes: It) -> &mut Self where
    T: ToString,
    It: IntoIterator<Item = T>, 
[src]

Sets the prefixes to respond to. Each can be a string slice of any non-zero length.

Note: Refer to prefix for the default value.

Examples

Assign a set of prefixes the bot can respond to:

use serenity::framework::StandardFramework;

client.with_framework(StandardFramework::new().configure(|c| c
    .prefixes(vec!["!", ">", "+"])));

pub fn no_dm_prefix(&mut self, b: bool) -> &mut Self[src]

Sets whether command execution can done without a prefix. Works only in private channels.

Note: Defaults to false.

Note

The cache feature is required. If disabled this does absolutely nothing.

pub fn delimiter<I: Into<Delimiter>>(&mut self, delimiter: I) -> &mut Self[src]

Sets a single delimiter to be used when splitting the content after a command.

Note: Defaults to a vector with a single element of ' '.

Examples

Have the args be separated by a comma and a space:

use serenity::framework::StandardFramework;

client.with_framework(StandardFramework::new().configure(|c| c
    .delimiter(", ")));

pub fn delimiters<T, It>(&mut self, delimiters: It) -> &mut Self where
    T: Into<Delimiter>,
    It: IntoIterator<Item = T>, 
[src]

Sets multiple delimiters to be used when splitting the content after a command. Additionally cleans the default delimiter from the vector.

Note: Refer to delimiter for the default value.

Examples

Have the args be separated by a comma and a space; and a regular space:

use serenity::framework::StandardFramework;

client.with_framework(StandardFramework::new().configure(|c| c
    .delimiters(vec![", ", " "])));

pub fn case_insensitivity(&mut self, cs: bool) -> &mut Self[src]

Whether the framework shouldn't care about the user's input if it's: ~command, ~Command, or ~COMMAND; mayacommand, MayACommand, MAYACOMMAND, et cetera.

Setting this to true will result in all prefixes and command names to be case insensitive.

Note: Defaults to false.

Trait Implementations

impl Default for Configuration[src]

fn default() -> Configuration[src]

Builds a default framework configuration, setting the following:

  • allow_dm to true
  • with_whitespace to (false, true, true)
  • by_space to true
  • blocked_guilds to an empty HashSet
  • blocked_users to an empty HashSet,
  • allowed_channels to an empty HashSet,
  • case_insensitive to false
  • delimiters to vec![' ']
  • disabled_commands to an empty HashSet
  • dynamic_prefixes to an empty vector
  • ignore_bots to true
  • ignore_webhooks to true
  • no_dm_prefix to false
  • on_mention to false
  • owners to an empty HashSet
  • prefix to an empty vector

Auto Trait Implementations

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

impl<T> Same<T> for T

type Output = T

Should always be Self

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

type Error = Infallible

The type returned in the event of a conversion error.

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

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> UnsafeAny for T where
    T: Any

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,