Trait serenity_utils::conversion::Conversion
source · [−]pub trait Conversion {
type Item;
fn from_guild_and_str<'life0, 'life1, 'async_trait>(
guild: &'life0 Guild,
arg: &'life1 str
) -> Pin<Box<dyn Future<Output = Option<Self::Item>> + Send + 'async_trait>>
where
Self: Sized,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn from_guild_id_and_str<'life0, 'life1, 'async_trait>(
ctx: &'life0 Context,
guild_id: GuildId,
arg: &'life1 str
) -> Pin<Box<dyn Future<Output = Option<Self::Item>> + Send + 'async_trait>>
where
Self: Sized,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
}
please use serenity’s ArgumentConvert trait
Expand description
A trait to convert a string into serenity’s models.
It provides two methods to convert a string into a guild-specific model.
The first method, from_guild_and_str
, is available only if cache is enabled.
The second method, from_guild_id_and_str
, is always available.
The second method tries to use the cache if it is enabled. Otherwise, it gets data over the REST API.
Conversion Strategy
Conversion follows this strategy:
- Converting argument into a ID and then fetching model using the ID.
- Converting argument into a mention and then fetching model using the extracted ID.
- Treating argument as model’s name.
Note: For Member
, nickname and user tag are considered along
with the user name.
Limitation
An argument is only treated as an ID or mention when trying to
convert to Member
if the cache
feature and the GUILDS
and GUILD_PRESENCES
intents are not enabled. It is not treated as
user name, nickname or tag.
Implementation
To implement this trait for a custom type, you have to implement both
from_guild_and_str
and from_guild_id_and_str
methods.
The strategy you use may depend on your model.
Required Associated Types
Required Methods
please use serenity’s ArgumentConvert trait
cache
only.Converts arg
into the specified type, if possible.
please use serenity’s ArgumentConvert trait
Implementations on Foreign Types
sourceimpl Conversion for Role
impl Conversion for Role
sourcefn from_guild_and_str<'life0, 'life1, 'async_trait>(
guild: &'life0 Guild,
arg: &'life1 str
) -> Pin<Box<dyn Future<Output = Option<Self>> + Send + 'async_trait>> where
Self: Sized,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
👎 Deprecated since 0.7.0: please use serenity’s ArgumentConvert trait
Available on crate feature cache
only.
fn from_guild_and_str<'life0, 'life1, 'async_trait>(
guild: &'life0 Guild,
arg: &'life1 str
) -> Pin<Box<dyn Future<Output = Option<Self>> + Send + 'async_trait>> where
Self: Sized,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
please use serenity’s ArgumentConvert trait
cache
only.Converts arg
into a Role
object.
sourcefn from_guild_id_and_str<'life0, 'life1, 'async_trait>(
ctx: &'life0 Context,
guild_id: GuildId,
arg: &'life1 str
) -> Pin<Box<dyn Future<Output = Option<Self::Item>> + Send + 'async_trait>> where
Self: Sized,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn from_guild_id_and_str<'life0, 'life1, 'async_trait>(
ctx: &'life0 Context,
guild_id: GuildId,
arg: &'life1 str
) -> Pin<Box<dyn Future<Output = Option<Self::Item>> + Send + 'async_trait>> where
Self: Sized,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
please use serenity’s ArgumentConvert trait
sourceimpl Conversion for Member
impl Conversion for Member
sourcefn from_guild_and_str<'life0, 'life1, 'async_trait>(
guild: &'life0 Guild,
arg: &'life1 str
) -> Pin<Box<dyn Future<Output = Option<Self>> + Send + 'async_trait>> where
Self: Sized,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
👎 Deprecated since 0.7.0: please use serenity’s ArgumentConvert trait
Available on crate feature cache
only.
fn from_guild_and_str<'life0, 'life1, 'async_trait>(
guild: &'life0 Guild,
arg: &'life1 str
) -> Pin<Box<dyn Future<Output = Option<Self>> + Send + 'async_trait>> where
Self: Sized,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
please use serenity’s ArgumentConvert trait
cache
only.Converts arg
into a Member
object.
sourcefn from_guild_id_and_str<'life0, 'life1, 'async_trait>(
ctx: &'life0 Context,
guild_id: GuildId,
arg: &'life1 str
) -> Pin<Box<dyn Future<Output = Option<Self::Item>> + Send + 'async_trait>> where
Self: Sized,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn from_guild_id_and_str<'life0, 'life1, 'async_trait>(
ctx: &'life0 Context,
guild_id: GuildId,
arg: &'life1 str
) -> Pin<Box<dyn Future<Output = Option<Self::Item>> + Send + 'async_trait>> where
Self: Sized,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
please use serenity’s ArgumentConvert trait
sourceimpl Conversion for GuildChannel
impl Conversion for GuildChannel
sourcefn from_guild_and_str<'life0, 'life1, 'async_trait>(
guild: &'life0 Guild,
arg: &'life1 str
) -> Pin<Box<dyn Future<Output = Option<Self>> + Send + 'async_trait>> where
Self: Sized,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
👎 Deprecated since 0.7.0: please use serenity’s ArgumentConvert trait
Available on crate feature cache
only.
fn from_guild_and_str<'life0, 'life1, 'async_trait>(
guild: &'life0 Guild,
arg: &'life1 str
) -> Pin<Box<dyn Future<Output = Option<Self>> + Send + 'async_trait>> where
Self: Sized,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
please use serenity’s ArgumentConvert trait
cache
only.Converts arg
into a GuildChannel
object.
type Item = GuildChannel
type Item = GuildChannel
please use serenity’s ArgumentConvert trait
sourcefn from_guild_id_and_str<'life0, 'life1, 'async_trait>(
ctx: &'life0 Context,
guild_id: GuildId,
arg: &'life1 str
) -> Pin<Box<dyn Future<Output = Option<Self::Item>> + Send + 'async_trait>> where
Self: Sized,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn from_guild_id_and_str<'life0, 'life1, 'async_trait>(
ctx: &'life0 Context,
guild_id: GuildId,
arg: &'life1 str
) -> Pin<Box<dyn Future<Output = Option<Self::Item>> + Send + 'async_trait>> where
Self: Sized,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
please use serenity’s ArgumentConvert trait