#[non_exhaustive]pub enum Channel {
Show 14 variants
Text(TextChannel),
Dm(DmChannel),
Voice(VoiceChannel),
GroupDm(GroupDmChannel),
Category(CategoryChannel),
Announcement(TextChannel),
AnnouncementThread(ThreadChannel),
PublicThread(ThreadChannel),
PrivateThread(ThreadChannel),
Stage(VoiceChannel),
Directory(DirectoryChannel),
Forum(ForumChannel),
Media(ForumChannel),
Unknown(UnknownChannel),
}Expand description
A channel of any kind (D-057).
Match on the variant to get the fields of a specific kind of channel, or use the methods for the fields most kinds share.
discord.js counterpart: Channel and its subclasses (TextChannel, VoiceChannel,
ThreadChannel, …).
§Examples
use djs_model::channel::{Channel, ChannelType};
let channel: Channel = serde_json::from_str(
r#"{"id":"41771983423143937","guild_id":"41771983423143937","name":"general",
"type":0,"position":6,"permission_overwrites":[],"rate_limit_per_user":2,
"nsfw":true,"topic":"24/7 chat about how to gank Mike #2",
"last_message_id":"155117677105512449","parent_id":"399942396007890945"}"#,
)?;
assert_eq!(channel.kind(), ChannelType::GuildText);
assert_eq!(channel.name(), Some("general"));
if let Channel::Text(text) = &channel {
assert_eq!(text.rate_limit_per_user, 2);
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Text(TextChannel)
A text channel in a guild (GUILD_TEXT).
Dm(DmChannel)
A direct message between two users (DM).
Voice(VoiceChannel)
A voice channel in a guild (GUILD_VOICE).
GroupDm(GroupDmChannel)
A direct message between several users (GROUP_DM).
Category(CategoryChannel)
A category that contains up to 50 channels (GUILD_CATEGORY).
Announcement(TextChannel)
An announcement channel whose messages can be followed and crossposted
(GUILD_ANNOUNCEMENT).
AnnouncementThread(ThreadChannel)
A thread in an announcement channel (ANNOUNCEMENT_THREAD).
PublicThread(ThreadChannel)
A public thread in a text, forum or media channel (PUBLIC_THREAD).
PrivateThread(ThreadChannel)
A private thread in a text channel (PRIVATE_THREAD).
Stage(VoiceChannel)
A stage channel for events with an audience (GUILD_STAGE_VOICE).
Directory(DirectoryChannel)
The channel of a Student Hub listing its servers (GUILD_DIRECTORY).
Forum(ForumChannel)
A channel that only contains threads (posts) (GUILD_FORUM).
Media(ForumChannel)
A forum-like channel for media posts (GUILD_MEDIA).
Unknown(UnknownChannel)
A kind of channel this version of the library does not know about (C-010).
Implementations§
Source§impl Channel
impl Channel
Sourcepub const fn kind(&self) -> ChannelType
pub const fn kind(&self) -> ChannelType
The kind of channel.
discord.js counterpart: BaseChannel#type.
Sourcepub const fn guild_id(&self) -> Option<GuildId>
pub const fn guild_id(&self) -> Option<GuildId>
The guild the channel belongs to. None for DMs, and for guild channels inside
GUILD_CREATE (where Discord omits it).
discord.js counterpart: GuildChannel#guildId.
Sourcepub fn name(&self) -> Option<&str>
pub fn name(&self) -> Option<&str>
The channel’s name. None for DMs and unnamed group DMs.
discord.js counterpart: GuildChannel#name.
Sourcepub const fn parent_id(&self) -> Option<ChannelId>
pub const fn parent_id(&self) -> Option<ChannelId>
The parent: the category of a guild channel, or the channel a thread was created in.
discord.js counterpart: GuildChannel#parentId.
Sourcepub const fn flags(&self) -> ChannelFlags
pub const fn flags(&self) -> ChannelFlags
The channel’s flags.
discord.js counterpart: BaseChannel#flags.
Sourcepub fn permission_overwrites(&self) -> &[Overwrite]
pub fn permission_overwrites(&self) -> &[Overwrite]
The permission overwrites of a guild channel; empty for DMs and threads.
discord.js counterpart: GuildChannel#permissionOverwrites.
Sourcepub const fn as_thread(&self) -> Option<&ThreadChannel>
pub const fn as_thread(&self) -> Option<&ThreadChannel>
Returns the thread data if this channel is a thread.
discord.js counterpart: BaseChannel#isThread.