View Source Nostrum.Struct.Channel (Nostrum v0.6.0)
Struct and helper functions for working with channels.
Channel Struct
The channel struct is used by Nostrum to represent a Discord Channel Object. More information can be found on the Discord API Channel Documentation.
The struct can have one of several forms depending on the type of channel. You can read more about the individual channel types below.
A typical channel would appear as:
%Nostrum.Struct.Channel{
guild_id: 766435015768539156,
id: 827333533688397865,
name: "announcements",
nsfw: false,
permission_overwrites: [],
position: 1,
type: 5,
}
The channel struct implements String.Chars
protocol through the mention/1
function. This example uses our channel from the previous code block.
channel |> to_string()
"<#766435015768539156>"
Channel Cache
The ChannelCache
module provides functionality for you to retrieve information about any channel that your application can see. It provides two functions: get/1
and get!/1
.
Example
Nostrum.Cache.ChannelCache.get!(827333533688397865)
%Nostrum.Struct.Channel{
application_id: nil,
bitrate: nil,
guild_id: 766435015768539156,
icon: nil,
id: 827333533688397865,
last_message_id: nil,
last_pin_timestamp: nil,
name: "announcements",
nsfw: false,
owner_id: nil,
parent_id: nil,
permission_overwrites: [
%Nostrum.Struct.Overwrite{
allow: 0,
deny: 2048,
id: 766435015768539156,
type: :role
}
],
position: 1,
recipients: nil,
topic: nil,
type: 5,
user_limit: nil
}
More details of the cache can be found at Nostrum.Cache.ChannelCache
.
Helper Functions
This module contains two functions for assisting with channel structs. mention/1
to convert the channel into a mention as a string, and link/1
to convert the channel into a hyperlink as a string. Further details and examples are detailed in the Functions section of this module.
Api Functions
The Nostrum Api contains numerous functions related to channels. Notable functions relating to channels are shown below.
Nostrum.Api.create_guild_channel/2
Nostrum.Api.get_channel/1
Nostrum.Api.modify_channel/3
Nostrum.Api.delete_channel/2
Nostrum.Api.add_pinned_channel_message/2
Nostrum.Api.create_channel_invite/3
Nostrum.Api.get_guild_channels/1
Nostrum.Api.modify_guild_channel_positions/2
Note: This is not an exhaustive list, for full details please see the
Nostrum.Api
module documentation.
Channel Types
Channels take the shape of various types depending on their use and not all fields are always used. The currently implemented channel types are detailed below. The type of channel is determined by the :type
field.
This diagram represents the regular channel types 0
, 2
, 5
and 13
.
The currently implemented channel types are:
Channel Type | ||
---|---|---|
0 | GUILD_TEXT | A text channel within a server |
1 | DM | A direct message between users |
2 | GUILD_VOICE | A voice channel within a server |
3 | GROUP_DM | A direct message between multiple users |
4 | GUILD_CATEGORY | A category that contains up to 50 channels |
5 | GUILD_NEWS | A channel that users can follow and crosspost |
6 | GUILD_STORE | A channel to sell games on Discord |
10 | GUILD_NEWS_THREAD | A temporary sub-channel within a news channel |
11 | GUILD_PUBLIC_THREAD | A temporary sub-channel within a text channel |
12 | GUILD_PRIVATE_THREAD | A temporary private sub-channel within a text channel |
13 | GUILD_STAGE_VOICE | A voice channel for hosting events with an audience |
More information about Discord Channel Types can be found on the Discord API Channel Type Documentation.
Link to this section Summary
Types
The id of the application that created a group direct message or thread.
When the thread was archived.
The threads archived status.
Archive duration for the thread in minutes.
The bitate of the voice channel.
A partial channel object representing a channel mention.
Default duration for newly created threads in minutes.
Type 1 partial channel object representing a direct message.
User thread settings, currently only used for notifications.
Type 3 partial channel object representing a group direct message.
Type 4 partial channel object representing a channel category.
Guild channel types
The id of the guild the channel is located in.
Type 5 partial channel object representing a news channel.
Type 10 partial channel object representing a news thread.
Type 12 partial channel object representing a private thread.
Type 11 partial channel object representing a standard thread.
Type 13 channel object representing a stage channel.
Type 6 partial channel object representing a store channel.
Type 0 partial channel object representing a text channel within a guild.
Type 2 partial channel object representing an audio channel within a guild.
The hash of the channels icon.
The id of the channel object.
When the user joined the thread.
The id of the last message sent in the channel.
Timestamp for the last pinned message.
The threads locked status.
Present when the bot joins a thread.
Approximate count of members in a thread, capped at 50.
Approximate count of messages in a thread, capped at 50.
The name of the channel.
Included only in the THREAD_CREATE
event.
Whether the NSFW setting is enabled for this channel.
The id of the user of a group direct message or thread.
The id of the parent channel that this channel is located under.
A list of permission overwrites applied to the channel.
Computed permissions of the invoking user.
The position of the channel in the sidebar of the guild.
The users rate limit.
A list of users in a group DM.
Region id for the channel.
All valid channel types.
All valid text channels.
The video quality mode of the voice channel.
The topic of the channel.
The type of channel.
User id of the threads creator.
The user limit of a voice channel.
The video quality mode of the channel.
A Nostrum.Struct.Channel
that represents a voice channel
Functions
Convert a channel into a mention.
Link to this section Types
Specs
application_id() :: Nostrum.Snowflake.t() | nil
The id of the application that created a group direct message or thread.
This applies to bot created channels.
Specs
archive_timestamp() :: DateTime.t() | nil
When the thread was archived.
Specs
archived() :: boolean()
The threads archived status.
Specs
auto_archive_duration() :: integer()
Archive duration for the thread in minutes.
- 60, 1 hour
- 1440, 24 hours
- 4320, 3 days
- 10080, 7 days
Specs
bitrate() :: integer()
The bitate of the voice channel.
Specs
channel_mention() :: %Nostrum.Struct.Channel{ application_id: term(), bitrate: term(), default_auto_archive_duration: term(), guild_id: guild_id(), icon: term(), id: id(), last_message_id: term(), last_pin_timestamp: term(), member: term(), member_count: term(), message_count: term(), name: name(), newly_created: term(), nsfw: term(), owner_id: term(), parent_id: term(), permission_overwrites: term(), permissions: term(), position: term(), rate_limit_per_user: term(), recipients: term(), rtc_region: term(), thread_metadata: term(), topic: term(), type: type(), user_limit: term(), video_quality_mode: term() }
A partial channel object representing a channel mention.
More information about the Discord Channel Mention Object can be found at the Discord API Channel Mention Object Documentation.
Specs
default_auto_archive_duration() :: integer()
Default duration for newly created threads in minutes.
- 60, 1 hour
- 1440, 24 hours
- 4320, 3 days
- 10080, 7 days
Specs
dm_channel() :: %Nostrum.Struct.Channel{ application_id: term(), bitrate: term(), default_auto_archive_duration: term(), guild_id: term(), icon: term(), id: id(), last_message_id: last_message_id(), last_pin_timestamp: last_pin_timestamp(), member: term(), member_count: term(), message_count: term(), name: term(), newly_created: term(), nsfw: term(), owner_id: term(), parent_id: term(), permission_overwrites: term(), permissions: term(), position: term(), rate_limit_per_user: term(), recipients: recipients(), rtc_region: term(), thread_metadata: term(), topic: term(), type: 1, user_limit: term(), video_quality_mode: term() }
Type 1 partial channel object representing a direct message.
Specs
flags() :: integer()
User thread settings, currently only used for notifications.
Specs
group_dm_channel() :: %Nostrum.Struct.Channel{ application_id: application_id(), bitrate: term(), default_auto_archive_duration: term(), guild_id: term(), icon: icon(), id: id(), last_message_id: last_message_id(), last_pin_timestamp: term(), member: term(), member_count: term(), message_count: term(), name: name(), newly_created: term(), nsfw: term(), owner_id: owner_id(), parent_id: term(), permission_overwrites: term(), permissions: term(), position: term(), rate_limit_per_user: term(), recipients: recipients(), rtc_region: term(), thread_metadata: term(), topic: term(), type: 3, user_limit: term(), video_quality_mode: term() }
Type 3 partial channel object representing a group direct message.
Specs
guild_category_channel() :: %Nostrum.Struct.Channel{ application_id: term(), bitrate: term(), default_auto_archive_duration: term(), guild_id: guild_id(), icon: term(), id: id(), last_message_id: term(), last_pin_timestamp: term(), member: term(), member_count: term(), message_count: term(), name: name(), newly_created: term(), nsfw: nsfw(), owner_id: term(), parent_id: parent_id(), permission_overwrites: permission_overwrites(), permissions: term(), position: position(), rate_limit_per_user: term(), recipients: term(), rtc_region: term(), thread_metadata: term(), topic: term(), type: 4, user_limit: term(), video_quality_mode: term() }
Type 4 partial channel object representing a channel category.
Note: Other channels
parent_id
field refers to this type of object.
Specs
guild_channel() :: guild_text_channel() | guild_voice_channel() | guild_category_channel()
Guild channel types
Specs
guild_id() :: Nostrum.Struct.Guild.id()
The id of the guild the channel is located in.
Specs
guild_news_channel() :: %Nostrum.Struct.Channel{ application_id: term(), bitrate: term(), default_auto_archive_duration: default_auto_archive_duration(), guild_id: guild_id(), icon: term(), id: id(), last_message_id: last_message_id(), last_pin_timestamp: term(), member: term(), member_count: term(), message_count: term(), name: name(), newly_created: term(), nsfw: nsfw(), owner_id: term(), parent_id: parent_id(), permission_overwrites: permission_overwrites(), permissions: term(), position: position(), rate_limit_per_user: term(), recipients: term(), rtc_region: term(), thread_metadata: term(), topic: topic(), type: 5, user_limit: term(), video_quality_mode: term() }
Type 5 partial channel object representing a news channel.
Specs
guild_news_thread_channel() :: %Nostrum.Struct.Channel{ application_id: term(), bitrate: term(), default_auto_archive_duration: term(), guild_id: guild_id(), icon: term(), id: id(), last_message_id: last_message_id(), last_pin_timestamp: term(), member: term(), member_count: member_count(), message_count: message_count(), name: name(), newly_created: newly_created(), nsfw: term(), owner_id: owner_id(), parent_id: parent_id(), permission_overwrites: term(), permissions: term(), position: term(), rate_limit_per_user: rate_limit_per_user(), recipients: term(), rtc_region: term(), thread_metadata: thread_metadata(), topic: term(), type: type(), user_limit: term(), video_quality_mode: term() }
Type 10 partial channel object representing a news thread.
Specs
guild_private_thread_channel() :: %Nostrum.Struct.Channel{ application_id: term(), bitrate: term(), default_auto_archive_duration: term(), guild_id: guild_id(), icon: term(), id: id(), last_message_id: last_message_id(), last_pin_timestamp: term(), member: term(), member_count: member_count(), message_count: message_count(), name: name(), newly_created: newly_created(), nsfw: term(), owner_id: owner_id(), parent_id: parent_id(), permission_overwrites: term(), permissions: term(), position: term(), rate_limit_per_user: rate_limit_per_user(), recipients: term(), rtc_region: term(), thread_metadata: thread_metadata(), topic: term(), type: type(), user_limit: term(), video_quality_mode: term() }
Type 12 partial channel object representing a private thread.
Specs
guild_public_thread_channel() :: %Nostrum.Struct.Channel{ application_id: term(), bitrate: term(), default_auto_archive_duration: term(), guild_id: guild_id(), icon: term(), id: id(), last_message_id: last_message_id(), last_pin_timestamp: term(), member: term(), member_count: member_count(), message_count: message_count(), name: name(), newly_created: newly_created(), nsfw: term(), owner_id: owner_id(), parent_id: parent_id(), permission_overwrites: term(), permissions: term(), position: term(), rate_limit_per_user: rate_limit_per_user(), recipients: term(), rtc_region: term(), thread_metadata: thread_metadata(), topic: term(), type: type(), user_limit: term(), video_quality_mode: term() }
Type 11 partial channel object representing a standard thread.
Specs
guild_stage_voice_channel() :: %Nostrum.Struct.Channel{ application_id: term(), bitrate: term(), default_auto_archive_duration: term(), guild_id: guild_id(), icon: term(), id: id(), last_message_id: last_message_id(), last_pin_timestamp: term(), member: term(), member_count: member_count(), message_count: message_count(), name: name(), newly_created: term(), nsfw: term(), owner_id: owner_id(), parent_id: parent_id(), permission_overwrites: term(), permissions: term(), position: term(), rate_limit_per_user: rate_limit_per_user(), recipients: term(), rtc_region: term(), thread_metadata: thread_metadata(), topic: term(), type: type(), user_limit: term(), video_quality_mode: term() }
Type 13 channel object representing a stage channel.
Specs
guild_store_channel() :: %Nostrum.Struct.Channel{ application_id: term(), bitrate: term(), default_auto_archive_duration: term(), guild_id: guild_id(), icon: term(), id: id(), last_message_id: term(), last_pin_timestamp: term(), member: term(), member_count: term(), message_count: term(), name: name(), newly_created: term(), nsfw: nsfw(), owner_id: term(), parent_id: parent_id(), permission_overwrites: permission_overwrites(), permissions: term(), position: position(), rate_limit_per_user: term(), recipients: term(), rtc_region: term(), thread_metadata: term(), topic: term(), type: type(), user_limit: term(), video_quality_mode: term() }
Type 6 partial channel object representing a store channel.
Specs
guild_text_channel() :: %Nostrum.Struct.Channel{ application_id: term(), bitrate: term(), default_auto_archive_duration: default_auto_archive_duration(), guild_id: guild_id(), icon: term(), id: id(), last_message_id: last_message_id(), last_pin_timestamp: term(), member: term(), member_count: term(), message_count: term(), name: name(), newly_created: term(), nsfw: nsfw(), owner_id: term(), parent_id: parent_id(), permission_overwrites: permission_overwrites(), permissions: term(), position: position(), rate_limit_per_user: rate_limit_per_user(), recipients: term(), rtc_region: term(), thread_metadata: term(), topic: topic(), type: type(), user_limit: term(), video_quality_mode: term() }
Type 0 partial channel object representing a text channel within a guild.
Specs
guild_voice_channel() :: %Nostrum.Struct.Channel{ application_id: term(), bitrate: bitrate(), default_auto_archive_duration: term(), guild_id: guild_id(), icon: term(), id: id(), last_message_id: term(), last_pin_timestamp: term(), member: term(), member_count: term(), message_count: term(), name: name(), newly_created: term(), nsfw: nsfw(), owner_id: term(), parent_id: parent_id(), permission_overwrites: permission_overwrites(), permissions: term(), position: position(), rate_limit_per_user: term(), recipients: term(), rtc_region: rtc_region(), thread_metadata: term(), topic: term(), type: 2, user_limit: user_limit(), video_quality_mode: term() }
Type 2 partial channel object representing an audio channel within a guild.
Specs
icon() :: String.t() | nil
The hash of the channels icon.
Specs
id() :: Nostrum.Snowflake.t()
The id of the channel object.
Specs
join_timestamp() :: DateTime.t()
When the user joined the thread.
Specs
last_message_id() :: Nostrum.Struct.Message.id() | nil
The id of the last message sent in the channel.
Specs
last_pin_timestamp() :: DateTime.t() | nil
Timestamp for the last pinned message.
Specs
locked() :: boolean()
The threads locked status.
Specs
member() :: %{ id: id(), user_id: user_id(), join_timestamp: join_timestamp(), flags: flags() }
Present when the bot joins a thread.
Note: This is omitted on threads that the bot can immediately access on :GUILD_CREATE
events received.
Specs
member_count() :: integer() | nil
Approximate count of members in a thread, capped at 50.
Specs
message_count() :: integer() | nil
Approximate count of messages in a thread, capped at 50.
Specs
name() :: String.t()
The name of the channel.
Specs
newly_created() :: boolean() | nil
Included only in the THREAD_CREATE
event.
Specs
nsfw() :: boolean()
Whether the NSFW setting is enabled for this channel.
Specs
owner_id() :: Nostrum.Struct.User.id()
The id of the user of a group direct message or thread.
This applies to user created channels.
Specs
parent_id() :: id() | nil
The id of the parent channel that this channel is located under.
For threads, that is the channel that contains the thread. For regular channels, it is the category that the channel is located under.
Specs
permission_overwrites() :: [Nostrum.Struct.Overwrite.t()]
A list of permission overwrites applied to the channel.
Specs
permissions() :: String.t()
Computed permissions of the invoking user.
Permissions for the invoking user in the channel, including overwrites, only included when part of the resolved data received on a slash command interaction
Specs
position() :: integer()
The position of the channel in the sidebar of the guild.
Specs
rate_limit_per_user() :: integer() | nil
The users rate limit.
Amount of seconds a user has to wait before sending another message (0-21600); bots, as well as users with the permission manage_messages or manage_channel, are unaffected
Specs
recipients() :: [Nostrum.Struct.User.t()]
A list of users in a group DM.
Specs
rtc_region() :: String.t() | nil
Region id for the channel.
More information about region ids can be found on the Discord API Voice Region Object Documentation.
Specs
t() :: guild_text_channel() | dm_channel() | guild_voice_channel() | group_dm_channel() | guild_category_channel() | guild_news_channel() | guild_store_channel() | guild_news_thread_channel() | guild_public_thread_channel() | guild_private_thread_channel() | guild_stage_voice_channel()
All valid channel types.
Specs
text_channel() :: guild_text_channel() | dm_channel() | group_dm_channel()
All valid text channels.
Specs
thread_metadata() :: %{ archived: archived(), auto_archive_duration: auto_archive_duration(), archive_timestamp: archive_timestamp(), locked: boolean() }
The video quality mode of the voice channel.
More information about video quality modes can be found on the Discord API Video Quality Mode Documentation.
Specs
topic() :: String.t()
The topic of the channel.
Specs
type() :: integer()
The type of channel.
More information about Discord Channel Types can be found under the types
on the Discord API Channel Type Documentation.
Specs
user_id() :: Nostrum.Snowflake.t() | nil
User id of the threads creator.
Specs
user_limit() :: integer()
The user limit of a voice channel.
Specs
video_quality_mode() :: integer() | nil
The video quality mode of the channel.
More information about video quality modes can be found on the Discord API Video Quality Mode Documentation.
Specs
voice_channel() :: guild_voice_channel()
A Nostrum.Struct.Channel
that represents a voice channel
Link to this section Functions
Specs
Convert a channel into a mention.
Handles the conversion of a Nostrum.Struct.Channel
into the required format to mention the channel within a message. Mentioning the channel will provide a clickable link to take the user to the channel.
Parameters
- channel:
Nostrum.Struct.Channel.t/0
Examples
Nostrum.Cache.ChannelCache.get(381889573426429952)
|> Nostrum.Struct.Channel.mention()
"<#381889573426429952>"