adiscord_types/api/channel.rs
1use crate::Snowflake;
2use super::{
3 forum,
4 reaction::DefaultReaction,
5 thread::{ThreadMember, ThreadMetadata},
6 user::User,
7};
8use serde::{Deserialize, Serialize};
9use serde_repr::{Deserialize_repr, Serialize_repr};
10
11#[repr(u8)]
12#[allow(non_camel_case_types)]
13#[derive(Deserialize_repr, Serialize_repr, Debug)]
14pub enum AttachmentFlags {
15 /// this attachment has been edited using the remix feature on mobile
16 IS_REMIX = 1 << 2
17}
18
19#[derive(Deserialize, Serialize, Debug)]
20pub struct Attachment {
21 /// attachment id
22 pub id: Snowflake,
23
24 /// name of file attached
25 pub filename: String,
26
27 /// description for the file (max 1024 characters)
28 pub description: Option<String>,
29
30 /// the attachment's media type
31 pub content_type: Option<String>,
32
33 /// size of file in bytes
34 pub size: u32,
35
36 /// source url of file
37 pub url: String,
38
39 /// a proxied url of file
40 pub proxy_url: String,
41
42 /// height of file (if image)
43 pub height: Option<u16>,
44
45 /// width of file (if image)
46 pub width: Option<u16>,
47
48 /// whether this attachment is ephemeral
49 pub ephemeral: Option<bool>,
50
51 /// the duration of the audio file (currently for voice messages)
52 pub duration_secs: Option<f32>,
53
54 /// base64 encoded bytearray representing a sampled waveform (currently for voice messages)
55 pub waveform: Option<String>,
56
57 /// attachment flags combined as a bitfield
58 pub flags: Option<AttachmentFlags>
59}
60
61#[repr(u16)]
62#[allow(non_camel_case_types)]
63#[derive(Deserialize_repr, Serialize_repr, Debug)]
64pub enum Flags {
65 None,
66
67 /// this thread is pinned to the top of its parent GUILD_FORUM or GUILD_MEDIA channel
68 PINNED = 1 << 1,
69
70 /// whether a tag is required to be specified when creating a thread in a GUILD_FORUM or a GUILD_MEDIA channel. Tags are specified in the applied_tags field.
71 REQUIRE_TAG = 1 << 4,
72
73 /// when set hides the embedded media download options. Available only for media channels
74 HIDE_MEDIA_DOWNLOAD_OPTIONS = 1 << 15
75}
76
77#[repr(u8)]
78#[allow(non_camel_case_types)]
79#[derive(Deserialize_repr, Serialize_repr, Debug)]
80pub enum ForumLayout {
81 /// No default has been set for forum channel
82 NOT_SET,
83
84 /// Display posts as a list
85 LIST_VIEW,
86
87 /// Display posts as a collection of tiles
88 GALLERY_VIEW,
89}
90
91#[derive(Deserialize, Serialize, Debug)]
92pub struct Mention {
93 /// id of the channel
94 pub id: Snowflake,
95
96 /// id of the guild containing the channel
97 pub guild_id: Snowflake,
98
99 /// the type of channel
100 pub r#type: ChannelType,
101
102 /// the name of the channel
103 pub name: String,
104}
105
106#[derive(Deserialize, Serialize, Debug)]
107pub struct Overwrite {
108 /// role or user id
109 pub id: Snowflake,
110
111 /// either 0 (role) or 1 (member)
112 pub r#type: u8,
113
114 /// permission bit set
115 pub allow: String,
116
117 /// permission bit set
118 pub deny: String,
119}
120
121#[repr(u8)]
122#[allow(non_camel_case_types)]
123#[derive(Deserialize_repr, Serialize_repr, Debug)]
124pub enum SortOrder {
125 /// Sort forum posts by activity
126 LATEST_ACTIVITY,
127
128 /// Sort forum posts by creation time (from most recent to oldest)
129 CREATION_DATE,
130}
131
132#[repr(u8)]
133#[allow(non_camel_case_types)]
134#[derive(Deserialize_repr, Serialize_repr, Debug)]
135pub enum ChannelType {
136 /// atext channel within a server
137 GUILD_TEXT,
138
139 /// a direct message between users
140 DM,
141
142 /// a voice channel within a server
143 GUILD_VOICE,
144
145 /// a direct message between multiple users
146 GROUP_DM,
147
148 /// an organizational category that contains up to 50 channels
149 GUILD_CATEGORY,
150
151 /// a channel that users can follow and crosspost into their own server (formerly news channels)
152 GUILD_ANNOUNCEMENT,
153
154 /// a temporary sub-channel within a GUILD_ANNOUNCEMENT channel
155 ANNOUNCEMENT_THREAD = 10,
156
157 /// a temporary sub-channel within a GUILD_TEXT or GUILD_FORUM channel
158 PUBLIC_THREAD,
159
160 /// a temporary sub-channel within a GUILD_TEXT channel that is only viewable by those invited and those with the MANAGE_THREADS permission
161 PRIVATE_THREAD,
162
163 /// a voice channel for hosting events with an audience
164 GUILD_STAGE_VOICE,
165
166 /// the channel in a hub containing the listed servers
167 GUILD_DIRECTORY,
168
169 /// Channel that can only contain threads
170 GUILD_FORUM,
171
172 /// Channel that can only contain threads, similar to GUILD_FORUM channels
173 GUILD_MEDIA
174}
175
176#[repr(u8)]
177#[derive(Deserialize_repr, Serialize_repr, Debug)]
178pub enum VideoQuality {
179 /// Discord chooses the quality for optimal performance
180 AUTO = 1,
181
182 /// 720p
183 FULL,
184}
185
186#[derive(Deserialize, Serialize, Debug)]
187pub struct Channel {
188 /// the id of this channel
189 pub id: Snowflake,
190
191 /// the type of channel
192 pub r#type: ChannelType,
193
194 // the id of the guild (may be missing for some channel objects received over gateway guild dispatches)
195 pub guild_id: Option<Snowflake>,
196
197 /// sorting position of the channel
198 pub position: Option<i32>,
199
200 /// explicit permission overwrites for members and roles
201 pub permission_overwrites: Option<Vec<Overwrite>>,
202
203 /// the name of the channel (1-100 characters)
204 pub name: Option<String>,
205
206 /// the channel topic (0-4096 characters for GUILD_FORUM and GUILD_MEDIA channels, 0-1024 characters for all others)
207 pub topic: Option<String>,
208
209 /// whether the channel is nsfw
210 pub nsfw: Option<bool>,
211
212 /// the id of the last message sent in this channel (or thread for GUILD_FORUM or GUILD_MEDIA channels) (may not point to an existing or valid message or thread)
213 pub last_message_id: Option<Snowflake>,
214
215 /// the bitrate (in bits) of the voice channel
216 pub bitrate: Option<i32>,
217
218 /// the user limit of the voice channel
219 pub user_limit: Option<u16>,
220
221 /// 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
222 pub rate_limit_per_user: Option<u16>,
223
224 /// the recipients of the DM
225 pub recipients: Option<Vec<User>>,
226
227 /// icon hash of the group DM
228 pub icon: Option<String>,
229
230 /// id of the creator of the group DM or thread
231 pub owner_id: Option<Snowflake>,
232
233 /// application id of the group DM creator if it is bot-created
234 pub application_id: Option<Snowflake>,
235
236 /// for group DM channels: whether the channel is managed by an application via the gdm.join OAuth2 scope
237 pub managed: Option<bool>,
238
239 /// for guild channels: id of the parent category for a channel (each parent category can contain up to 50 channels), for threads: id of the text channel this thread was created
240 pub parent_id: Option<Snowflake>,
241
242 /// when the last pinned message was pinned. This may be null in events such as GUILD_CREATE when a message is not pinned.
243 pub last_pin_timestamp: Option<String>,
244
245 /// voice region id for the voice channel, automatic when set to null
246 pub rtc_region: Option<String>,
247
248 /// the camera video quality mode of the voice channel, 1 when not present
249 pub video_quality_mode: Option<VideoQuality>,
250
251 /// number of messages (not including the initial message or deleted messages) in a thread.
252 pub message_count: Option<i32>,
253
254 /// an approximate count of users in a thread, stops counting at 50
255 pub member_count: Option<u8>,
256
257 /// thread-specific fields not needed by other channels
258 pub thread_metadata: Option<ThreadMetadata>,
259
260 /// thread member object for the current user, if they have joined the thread, only included on certain API endpoints
261 pub member: Option<ThreadMember>,
262
263 /// default duration, copied onto newly created threads, in minutes, threads will stop showing in the channel list after the specified period of inactivity, can be set to: 60, 1440, 4320, 10080
264 pub default_auto_archive_duration: Option<u16>,
265
266 /// computed permissions for the invoking user in the channel, including overwrites, only included when part of the resolved data received on a slash command interaction. This does not include implicit permissions, which may need to be checked separately
267 pub permissions: Option<String>,
268
269 /// channel flags combined as a bitfield
270 pub flags: Option<Flags>,
271
272 /// number of messages ever sent in a thread, it's similar to message_count on message creation, but will not decrement the number when a message is deleted
273 pub total_message_sent: Option<i32>,
274
275 /// the set of tags that can be used in a GUILD_FORUM or a GUILD_MEDIA channel
276 pub available_tags: Option<Vec<forum::Tags>>,
277
278 /// the IDs of the set of tags that have been applied to a thread in a GUILD_FORUM or a GUILD_MEDIA channel
279 pub applied_tags: Option<Vec<Snowflake>>,
280
281 /// the emoji to show in the add reaction button on a thread in a GUILD_FORUM or a GUILD_MEDIA channel
282 pub default_reaction_emoji: Option<DefaultReaction>,
283
284 /// the initial rate_limit_per_user to set on newly created threads in a channel. this field is copied to the thread at creation time and does not live update.
285 pub default_thread_rate_limit_per_user: Option<i32>,
286
287 /// the default sort order type used to order posts in GUILD_FORUM and GUILD_MEDIA channels. Defaults to null, which indicates a preferred sort order hasn't been set by a channel admin
288 pub default_sort_order: Option<SortOrder>,
289
290 /// the default forum layout view used to display posts in GUILD_FORUM channels. Defaults to 0, which indicates a layout view has not been set by a channel admin
291 pub default_forum_layout: Option<ForumLayout>,
292}