Struct serenity::framework::standard::Configuration
[−]
[src]
pub struct Configuration { /* fields omitted */ }
The configuration to use for a Framework
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.
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; let mut client = Client::new(&env::var("DISCORD_BOT_TOKEN").unwrap(), Handler); client.with_framework(StandardFramework::new() .configure(|c| c.on_mention(true).prefix("~")));
Methods
impl Configuration
[src]
fn allow_dm(self, allow_dm: bool) -> Self
[src]
If set to false, bot will ignore any private messages.
fn allow_whitespace(self, allow_whitespace: bool) -> Self
[src]
Whether to allow whitespace being optional between a mention/prefix and a command.
Note: Defaults to false
.
Examples
Setting this to false
will only allow this scenario to occur:
<@245571012924538880> about !about // bot processes and executes the "about" command if it exists
while setting this to true
will also allow this scenario to occur:
<@245571012924538880>about ! about // bot processes and executes the "about" command if it exists
fn blocked_guilds(self, guilds: HashSet<GuildId>) -> Self
[src]
HashSet of guild Ids where commands will be ignored.
Examples
Create a HashSet in-place:
use serenity::model::GuildId; use serenity::framework::StandardFramework; client.with_framework(StandardFramework::new().configure(|c| c .blocked_guilds(vec![GuildId(7), GuildId(77)].into_iter().collect())));
fn blocked_users(self, users: HashSet<UserId>) -> Self
[src]
HashSet of user Ids whose commands will be ignored. Guilds owned by user Ids will also be ignored.
Examples
Create a HashSet in-place:
use serenity::model::UserId; use serenity::framework::StandardFramework; client.with_framework(StandardFramework::new().configure(|c| c .blocked_users(vec![UserId(7), UserId(77)].into_iter().collect())));
fn depth(self, depth: u8) -> Self
[src]
The default depth of the message to check for commands. Defaults to 5. This determines how "far" into a message to check for a valid command.
Examples
If you set a depth of 1
, and make a command of "music play"
, but
not a "music"
command, then the former command will never be
triggered, as its "depth" is 2
.
fn disabled_commands(self, commands: HashSet<String>) -> Self
[src]
HashSet of command names that won't be run.
Examples
Ignore a set of commands, assuming they exist:
use serenity::framework::StandardFramework; let disabled = vec!["ping"].into_iter().map(|x| x.to_owned()).collect(); client.with_framework(StandardFramework::new() .command("ping", |c| c.exec_str("pong!")) .configure(|c| c.disabled_commands(disabled)));
fn dynamic_prefix<F>(self, dynamic_prefix: F) -> Self where
F: Fn(&mut Context, &Message) -> Option<String> + Send + Sync + 'static,
[src]
F: Fn(&mut Context, &Message) -> Option<String> + Send + Sync + 'static,
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.
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() .command("ping", |c| c.exec_str("Pong!")) .configure(|c| c.dynamic_prefix(|_, msg| { Some(if msg.channel_id.0 % 5 == 0 { "!" } else { "~" }.to_owned()) })));
fn ignore_bots(self, ignore_bots: bool) -> 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.
fn ignore_webhooks(self, ignore_webhooks: bool) -> Self
[src]
If set to true, bot will ignore all commands called by webhooks. True by default.
fn on_mention(self, on_mention: bool) -> Self
[src]
Whether or not to respond to commands initiated with a mention. Note
that this can be used in conjunction with prefix
.
By default this is set to false
.
Examples
Setting this to true
will allow the following types of mentions to be
responded to:
<@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.
fn owners(self, user_ids: HashSet<UserId>) -> Self
[src]
A HashSet
of user Ids checks won't apply to.
Examples
Create a HashSet in-place:
use serenity::model::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::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)));
fn prefix(self, prefix: &str) -> Self
[src]
Sets the prefix to respond to. A prefix can be a string slice of any non-zero length.
Examples
Assign a basic prefix:
use serenity::framework::StandardFramework; client.with_framework(StandardFramework::new().configure(|c| c .prefix("!")));
fn prefixes(self, prefixes: Vec<&str>) -> Self
[src]
Sets the prefixes to respond to. Each can be a string slice of any non-zero length.
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!["!", ">", "+"])));
fn delimiter(self, delimiter: &str) -> Self
[src]
Sets a delimiter to be used when splitting the content after a command.
Examples
Have the args be seperated by a comma and a space:
use serenity::framework::StandardFramework; client.with_framework(StandardFramework::new().configure(|c| c .delimiter(", ")));
fn delimiters(self, delimiters: Vec<&str>) -> Self
[src]
Sets multiple delimiters to be used when splitting the content after a command. Additionally cleans the default delimiter from the vector.
Examples
Have the args be seperated by a comma and a space; and a regular space:
use serenity::framework::StandardFramework; client.with_framework(StandardFramework::new().configure(|c| c .delimiters(vec![", ", " "])));
fn case_insensitivity(self, cs: bool) -> Self
[src]
Whether the framework shouldn't care about the user's input if it's: ~command
,
~Command
, ~COMMAND
.
Setting this to true
will result in all command names to be case insensitive.
Trait Implementations
impl Default for Configuration
[src]
fn default() -> Configuration
[src]
Builds a default framework configuration, setting the following:
- allow_whitespace to
false
- depth to
5
- on_mention to
false
(basically) - prefix to
None
- delimiters to vec![" "]
- case_insensitive to
false