[−][src]Struct serenity::framework::standard::Configuration
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; 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(true).prefix("~")));
Methods
impl Configuration
[src]
impl Configuration
pub fn allow_dm(self, allow_dm: bool) -> Self
[src]
pub fn allow_dm(self, allow_dm: bool) -> Self
If set to false, bot will ignore any private messages.
Note: Defaults to true
.
pub fn allow_whitespace(self, allow_whitespace: bool) -> Self
[src]
pub fn allow_whitespace(self, allow_whitespace: bool) -> Self
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
pub fn allowed_channels(self, channels: HashSet<ChannelId>) -> Self
[src]
pub fn allowed_channels(self, channels: HashSet<ChannelId>) -> Self
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(self, guilds: HashSet<GuildId>) -> Self
[src]
pub fn blocked_guilds(self, guilds: HashSet<GuildId>) -> Self
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(self, users: HashSet<UserId>) -> Self
[src]
pub fn blocked_users(self, users: HashSet<UserId>) -> Self
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 depth(self, depth: u8) -> Self
[src]
pub fn depth(self, depth: u8) -> Self
The default depth of the message to check for commands.
This determines how "far" into a message to check for a valid command.
Note: Defaults to 5.
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
.
pub fn disabled_commands(self, commands: HashSet<String>) -> Self
[src]
pub fn disabled_commands(self, commands: HashSet<String>) -> Self
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; let disabled = vec!["ping"].into_iter().map(|x| x.to_string()).collect(); client.with_framework(StandardFramework::new() .on("ping", |_, msg, _| { msg.channel_id.say("Pong!")?; Ok(()) }) .configure(|c| c.disabled_commands(disabled)));
pub fn dynamic_prefix<F>(self, dynamic_prefix: F) -> Self where
F: Fn(&mut Context, &Message) -> Option<String> + Send + Sync + 'static,
[src]
pub fn dynamic_prefix<F>(self, dynamic_prefix: F) -> Self where
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.
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() .on("ping", |_, msg, _| { msg.channel_id.say("Pong!")?; Ok(()) }) .configure(|c| c.dynamic_prefix(|_, msg| { Some(if msg.channel_id.0 % 5 == 0 { "!" } else { "~" }.to_string()) })));
pub fn ignore_bots(self, ignore_bots: bool) -> Self
[src]
pub fn ignore_bots(self, ignore_bots: bool) -> Self
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(self, ignore_webhooks: bool) -> Self
[src]
pub fn ignore_webhooks(self, ignore_webhooks: bool) -> Self
If set to true, bot will ignore all commands called by webhooks.
Note: Defaults to true
.
pub fn on_mention(self, on_mention: bool) -> Self
[src]
pub fn on_mention(self, on_mention: bool) -> Self
Whether or not to respond to commands initiated with a mention. Note
that this can be used in conjunction with prefix
.
Note: Defaults 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.
pub fn owners(self, user_ids: HashSet<UserId>) -> Self
[src]
pub fn owners(self, user_ids: HashSet<UserId>) -> Self
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(self, prefix: &str) -> Self
[src]
pub fn prefix(self, prefix: &str) -> Self
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: ToString, It: IntoIterator<Item = T>>(
self,
prefixes: It
) -> Self
[src]
pub fn prefixes<T: ToString, It: IntoIterator<Item = T>>(
self,
prefixes: It
) -> Self
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(self, b: bool) -> Self
[src]
pub fn no_dm_prefix(self, b: bool) -> Self
Sets whether command execution can done without a prefix. Works only in private channels.
Note: Defaults to false
.
Note
Needs the cache
feature to be enabled. Otherwise this does nothing.
pub fn delimiter(self, delimiter: &str) -> Self
[src]
pub fn delimiter(self, delimiter: &str) -> Self
Sets a 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: ToString, It: IntoIterator<Item = T>>(
self,
delimiters: It
) -> Self
[src]
pub fn delimiters<T: ToString, It: IntoIterator<Item = T>>(
self,
delimiters: It
) -> Self
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(self, cs: bool) -> Self
[src]
pub fn case_insensitivity(self, cs: bool) -> Self
Whether the framework shouldn't care about the user's input if it's:
~command
, ~Command
, or ~COMMAND
.
Setting this to true
will result in all command names to be case
insensitive.
Note: Defaults to false
.
pub fn prefix_only_cmd<C: Command + 'static>(self, c: C) -> Self
[src]
pub fn prefix_only_cmd<C: Command + 'static>(self, c: C) -> Self
Sets a command to dispatch if user's input is a prefix only.
Note: Defaults to no command and ignores prefix only.
Trait Implementations
impl Default for Configuration
[src]
impl Default for Configuration
fn default() -> Configuration
[src]
fn default() -> Configuration
Builds a default framework configuration, setting the following:
- allow_dm to
true
- allow_whitespace to
false
- allowed_channels to an empty HashSet
- blocked_guilds to an empty HashSet
- blocked_users to an empty HashSet
- case_insensitive to
false
- delimiters to
vec![" "]
- depth to
5
- disabled_commands to an empty HashSet
- dynamic_prefix to no dynamic prefix check
- ignore_bots to
true
- ignore_webhooks to
true
- no_dm_prefix to
false
- on_mention to
false
(basically) - owners to an empty HashSet
- prefix to an empty vector
Auto Trait Implementations
impl Send for Configuration
impl Send for Configuration
impl Sync for Configuration
impl Sync for Configuration
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,