pub trait ArgumentConvert: Sized {
type Err;
// Required method
fn convert<'life0, 'async_trait>(
ctx: impl 'async_trait + CacheHttp,
guild_id: Option<GuildId>,
channel_id: Option<ChannelId>,
s: &'life0 str,
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Err>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}
Expand description
Parse a value from a string in context of a received message.
This trait is a superset of std::str::FromStr
. The difference is that this trait aims to
support serenity-specific Discord types like Member
or Message
.
Trait implementations may do network requests as part of their parsing procedure.
Useful for implementing argument parsing in command frameworks.
Required Associated Types§
Required Methods§
Sourcefn convert<'life0, 'async_trait>(
ctx: impl 'async_trait + CacheHttp,
guild_id: Option<GuildId>,
channel_id: Option<ChannelId>,
s: &'life0 str,
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Err>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn convert<'life0, 'async_trait>(
ctx: impl 'async_trait + CacheHttp,
guild_id: Option<GuildId>,
channel_id: Option<ChannelId>,
s: &'life0 str,
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Err>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Parses a string s
as a command parameter of this type.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
Source§impl ArgumentConvert for Channel
Look up a Channel by a string case-insensitively.
impl ArgumentConvert for Channel
Look up a Channel by a string case-insensitively.
Lookup are done via local guild. If in DMs, the global cache is used instead.
The cache feature needs to be enabled.
The lookup strategy is as follows (in order):
- Lookup by ID.
- Lookup by mention.
- Lookup by name.
type Err = ChannelParseError
Source§impl ArgumentConvert for GuildChannel
Look up a GuildChannel by a string case-insensitively.
impl ArgumentConvert for GuildChannel
Look up a GuildChannel by a string case-insensitively.
Lookup is done by the global cache, hence the cache feature needs to be enabled.
For more information, see the ArgumentConvert implementation for Channel
type Err = GuildChannelParseError
Source§impl ArgumentConvert for Message
Look up a message by a string.
impl ArgumentConvert for Message
Look up a message by a string.
The lookup strategy is as follows (in order):
- Lookup by “{channel ID}-{message ID}” (retrieved by shift-clicking on “Copy ID”)
- Lookup by message ID (the message must be in the context channel)
- Lookup by message URL
type Err = MessageParseError
Source§impl ArgumentConvert for Emoji
Look up a Emoji
.
impl ArgumentConvert for Emoji
Look up a Emoji
.
Requires the cache feature to be enabled.
The lookup strategy is as follows (in order):
- Lookup by ID.
- Lookup by extracting ID from the emoji.
- Lookup by name.
type Err = EmojiParseError
Source§impl ArgumentConvert for Guild
Look up a Guild, either by ID or by a string case-insensitively.
impl ArgumentConvert for Guild
Look up a Guild, either by ID or by a string case-insensitively.
Requires the cache feature to be enabled.
type Err = GuildParseError
Source§impl ArgumentConvert for Member
Look up a guild member by a string case-insensitively.
impl ArgumentConvert for Member
Look up a guild member by a string case-insensitively.
Requires the cache feature to be enabled.
The lookup strategy is as follows (in order):
- Lookup by ID.
- Lookup by mention.
- Lookup by name#discrim.
- Lookup by name
- Lookup by nickname
type Err = MemberParseError
Source§impl ArgumentConvert for Role
Look up a Role
by a string case-insensitively.
impl ArgumentConvert for Role
Look up a Role
by a string case-insensitively.
Requires the cache feature to be enabled.
The lookup strategy is as follows (in order):
- Lookup by ID
- Lookup by mention.
- Lookup by name (case-insensitive)
type Err = RoleParseError
Source§impl ArgumentConvert for User
Look up a user by a string case-insensitively.
impl ArgumentConvert for User
Look up a user by a string case-insensitively.
Requires the cache feature to be enabled. If a user is not in cache, they will not be found!
The lookup strategy is as follows (in order):
- Lookup by ID.
- Lookup by mention.
- Lookup by name#discrim.
- Lookup by name