#[non_exhaustive]pub enum Channel {
Guild(GuildChannel),
Private(PrivateChannel),
}
Expand description
A container for any channel.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Guild(GuildChannel)
A channel within a Guild
.
Private(PrivateChannel)
A private channel to another User
(Direct Message). No other users may access the
channel.
Implementations§
source§impl Channel
impl Channel
sourcepub fn guild(self) -> Option<GuildChannel>
Available on crate feature model
only.
pub fn guild(self) -> Option<GuildChannel>
model
only.Converts from Channel
to Option<GuildChannel>
.
Converts self
into an Option<GuildChannel>
, consuming self
, and discarding a
PrivateChannel
if any.
§Examples
Basic usage:
match channel.guild() {
Some(guild_channel) => {
println!("It's a guild channel named {}!", guild_channel.name);
},
None => {
println!("It's not in a guild!");
},
}
sourcepub fn private(self) -> Option<PrivateChannel>
Available on crate feature model
only.
pub fn private(self) -> Option<PrivateChannel>
model
only.Converts from Channel
to Option<PrivateChannel>
.
Converts self
into an Option<PrivateChannel>
, consuming self
, and discarding a
GuildChannel
, if any.
§Examples
Basic usage:
match channel.private() {
Some(private) => {
println!("It's a private channel with {}!", &private.recipient);
},
None => {
println!("It's not a private channel!");
},
}
sourcepub fn category(self) -> Option<GuildChannel>
Available on crate feature model
only.
pub fn category(self) -> Option<GuildChannel>
model
only.If this is a category channel, returns it.
sourcepub async fn delete(&self, cache_http: impl CacheHttp) -> Result<()>
Available on crate feature model
only.
pub async fn delete(&self, cache_http: impl CacheHttp) -> Result<()>
model
only.Deletes the inner channel.
§Errors
If the cache
is enabled, returns ModelError::InvalidPermissions
, if the current user
lacks permission.
Otherwise will return Error::Http
if the current user does not have permission.
sourcepub fn is_nsfw(&self) -> bool
👎Deprecated: Use the GuildChannel::nsfw field, as PrivateChannel is never NSFWAvailable on crate feature model
only.
pub fn is_nsfw(&self) -> bool
model
only.Determines if the channel is NSFW.
sourcepub const fn id(&self) -> ChannelId
Available on crate feature model
only.
pub const fn id(&self) -> ChannelId
model
only.Retrieves the Id of the inner GuildChannel
, or PrivateChannel
.
sourcepub const fn position(&self) -> Option<u16>
Available on crate feature model
only.
pub const fn position(&self) -> Option<u16>
model
only.Retrieves the position of the inner GuildChannel
.
In DMs (private channel) it will return None.
Trait Implementations§
source§impl ArgumentConvert for Channel
Available on crate features client
and utils
only.
impl ArgumentConvert for Channel
client
and utils
only.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
type Err = ChannelParseError
source§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,
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,
s
as a command parameter of this type.source§impl<'de> Deserialize<'de> for Channel
impl<'de> Deserialize<'de> for Channel
source§fn deserialize<D: Deserializer<'de>>(
deserializer: D
) -> StdResult<Self, D::Error>
fn deserialize<D: Deserializer<'de>>( deserializer: D ) -> StdResult<Self, D::Error>
source§impl Display for Channel
impl Display for Channel
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the channel into a “mentioned” string.
This will return a different format for each type of channel:
PrivateChannel
s: the recipient’s name;GuildChannel
s: a string mentioning the channel that users who can see the channel can click on.