Skip to main content

Channel

Enum Channel 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

Source

pub const fn id(&self) -> ChannelId

The channel’s ID.

discord.js counterpart: BaseChannel#id.

Source

pub const fn kind(&self) -> ChannelType

The kind of channel.

discord.js counterpart: BaseChannel#type.

Source

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.

Source

pub fn name(&self) -> Option<&str>

The channel’s name. None for DMs and unnamed group DMs.

discord.js counterpart: GuildChannel#name.

Source

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.

Source

pub const fn flags(&self) -> ChannelFlags

The channel’s flags.

discord.js counterpart: BaseChannel#flags.

Source

pub fn permission_overwrites(&self) -> &[Overwrite]

The permission overwrites of a guild channel; empty for DMs and threads.

discord.js counterpart: GuildChannel#permissionOverwrites.

Source

pub const fn as_thread(&self) -> Option<&ThreadChannel>

Returns the thread data if this channel is a thread.

discord.js counterpart: BaseChannel#isThread.

Trait Implementations§

Source§

impl Clone for Channel

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Channel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Channel

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Channel

Source§

impl From<ChannelCreate> for Channel

Source§

fn from(event: ChannelCreate) -> Self

Converts to this type from the input type.
Source§

impl From<ChannelDelete> for Channel

Source§

fn from(event: ChannelDelete) -> Self

Converts to this type from the input type.
Source§

impl From<ChannelUpdate> for Channel

Source§

fn from(event: ChannelUpdate) -> Self

Converts to this type from the input type.
Source§

impl From<ThreadUpdate> for Channel

Source§

fn from(event: ThreadUpdate) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Channel

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Channel

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Channel

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.