glyde/payload/channel
Bodies for creating and editing channels and threads.
The enums here are send-only, so none of them has an unknown tail: a value
Discord does not know is a 400, not something to survive. Each holds the
values its endpoint accepts and nothing else, and glyde/model/channel
stays the one place the wire numbers live.
PATCH /channels/{id} takes two structurally different bodies at one URL,
so a guild channel and a thread are two types with an encoder each. On an
edit null is an instruction, which is what Field is for; a create has
nothing to clear, so it uses Option.
Types
Minutes, and Discord takes only these four.
pub type AutoArchiveDuration {
OneHour
OneDay
ThreeDays
OneWeek
}
Constructors
-
OneHour -
OneDay -
ThreeDays -
OneWeek
The only conversion PATCH /channels/{id} does: text to announcement and
back, in a guild with the NEWS feature.
pub type ChannelConversion {
ToText
ToAnnouncement
}
Constructors
-
ToText -
ToAnnouncement
What POST /guilds/{g}/channels can create. Threads come from the thread
routes and a DM is not a guild channel, so neither is in here.
pub type CreatableChannelType {
TextChannel
VoiceChannel
CategoryChannel
AnnouncementChannel
StageChannel
ForumChannel
MediaChannel
}
Constructors
-
TextChannel -
VoiceChannel -
CategoryChannel -
AnnouncementChannel -
StageChannel -
ForumChannel -
MediaChannel
POST /guilds/{g}/channels. Only name is required.
pub type CreateChannel {
CreateChannel(
name: String,
type_: option.Option(CreatableChannelType),
topic: option.Option(String),
bitrate: option.Option(Int),
user_limit: option.Option(Int),
rate_limit_per_user: option.Option(Int),
position: option.Option(Int),
permission_overwrites: option.Option(List(OverwriteBody)),
parent_id: option.Option(id.Id(id.Channel)),
nsfw: option.Option(Bool),
rtc_region: option.Option(String),
video_quality_mode: option.Option(VideoQuality),
default_auto_archive_duration: option.Option(
AutoArchiveDuration,
),
default_thread_rate_limit_per_user: option.Option(Int),
flags: option.Option(List(SettableChannelFlag)),
)
}
Constructors
-
CreateChannel( name: String, type_: option.Option(CreatableChannelType), topic: option.Option(String), bitrate: option.Option(Int), user_limit: option.Option(Int), rate_limit_per_user: option.Option(Int), position: option.Option(Int), permission_overwrites: option.Option(List(OverwriteBody)), parent_id: option.Option(id.Id(id.Channel)), nsfw: option.Option(Bool), rtc_region: option.Option(String), video_quality_mode: option.Option(VideoQuality), default_auto_archive_duration: option.Option( AutoArchiveDuration, ), default_thread_rate_limit_per_user: option.Option(Int), flags: option.Option(List(SettableChannelFlag)), )Arguments
- name
-
1 to 100 characters.
- type_
-
Discord defaults this to a text channel.
- rate_limit_per_user
-
Seconds.
- default_auto_archive_duration
-
Minutes.
- flags
-
The complete set, not an addition: Discord reads
flagsas the whole bitfield, so a flag left out of the list is off.
POST /channels/{c}/threads. type_ is required rather than optional:
leaving it out gets a private thread today, and Discord has said that
default will change.
pub type CreateThread {
CreateThread(
name: String,
type_: ThreadType,
auto_archive_duration: option.Option(AutoArchiveDuration),
invitable: option.Option(Bool),
rate_limit_per_user: option.Option(Int),
)
}
Constructors
-
CreateThread( name: String, type_: ThreadType, auto_archive_duration: option.Option(AutoArchiveDuration), invitable: option.Option(Bool), rate_limit_per_user: option.Option(Int), )Arguments
- invitable
-
Private threads only.
POST /channels/{c}/messages/{m}/threads. The thread takes the source
message’s id, so a message can only ever have one.
pub type CreateThreadFromMessage {
CreateThreadFromMessage(
name: String,
auto_archive_duration: option.Option(AutoArchiveDuration),
rate_limit_per_user: option.Option(Int),
)
}
Constructors
-
CreateThreadFromMessage( name: String, auto_archive_duration: option.Option(AutoArchiveDuration), rate_limit_per_user: option.Option(Int), )
PATCH /channels/{id} for a guild channel. Group DM edits are out of v1.
pub type EditGuildChannel {
EditGuildChannel(
name: option.Option(String),
type_: option.Option(ChannelConversion),
position: field.Field(Int),
topic: field.Field(String),
nsfw: field.Field(Bool),
rate_limit_per_user: field.Field(Int),
bitrate: field.Field(Int),
user_limit: field.Field(Int),
permission_overwrites: field.Field(List(OverwriteBody)),
parent_id: field.Field(id.Id(id.Channel)),
rtc_region: field.Field(String),
video_quality_mode: field.Field(VideoQuality),
default_auto_archive_duration: field.Field(
AutoArchiveDuration,
),
default_thread_rate_limit_per_user: option.Option(Int),
flags: option.Option(List(SettableChannelFlag)),
)
}
Constructors
-
EditGuildChannel( name: option.Option(String), type_: option.Option(ChannelConversion), position: field.Field(Int), topic: field.Field(String), nsfw: field.Field(Bool), rate_limit_per_user: field.Field(Int), bitrate: field.Field(Int), user_limit: field.Field(Int), permission_overwrites: field.Field(List(OverwriteBody)), parent_id: field.Field(id.Id(id.Channel)), rtc_region: field.Field(String), video_quality_mode: field.Field(VideoQuality), default_auto_archive_duration: field.Field(AutoArchiveDuration), default_thread_rate_limit_per_user: option.Option(Int), flags: option.Option(List(SettableChannelFlag)), )Arguments
- permission_overwrites
-
A list replaces the whole set, never merges.
Nullmeans no overwrites at all. Leaving them alone isAbsent. - parent_id
-
Nullmoves the channel out of its category. - rtc_region
-
Nullhands region selection back to Discord. - flags
-
The complete set, not an addition: Discord reads
flagsas the whole bitfield, so a flag left out of the list is off.
PATCH /channels/{id} for a thread, which shares the URL with
EditGuildChannel and nothing else.
pub type EditThread {
EditThread(
name: option.Option(String),
archived: option.Option(Bool),
auto_archive_duration: option.Option(AutoArchiveDuration),
locked: option.Option(Bool),
invitable: option.Option(Bool),
rate_limit_per_user: field.Field(Int),
pinned: option.Option(Bool),
)
}
Constructors
-
EditThread( name: option.Option(String), archived: option.Option(Bool), auto_archive_duration: option.Option(AutoArchiveDuration), locked: option.Option(Bool), invitable: option.Option(Bool), rate_limit_per_user: field.Field(Int), pinned: option.Option(Bool), )Arguments
- invitable
-
Private threads only.
- pinned
-
PINNED, the whole of what
flagscan say on a thread. A post in a forum or media channel only.
One permission overwrite as it goes out.
Opaque because Discord reads type to decide what the id means: a role id
under type: 1 is not an error, it applies the overwrite to whichever
member happens to have that id. The two constructors are the only way in,
so the pair cannot disagree.
pub opaque type OverwriteBody
The two channel flags a create or an edit may set. The rest of Discord’s channel-flags table is read-only: PINNED belongs to a forum post rather than a channel, and IS_SPOILER_CHANNEL is not settable over the API at all.
pub type SettableChannelFlag {
RequireTag
HideMediaDownloadOptions
}
Constructors
-
RequireTagEvery post in the forum must carry a tag. Forum channels only.
-
HideMediaDownloadOptionsMedia channels only.
The kinds POST /channels/{c}/threads creates.
pub type ThreadType {
PublicThread
PrivateThread
AnnouncementThread
}
Constructors
-
PublicThread -
PrivateThread -
AnnouncementThread
pub type VideoQuality {
AutoQuality
FullQuality
}
Constructors
-
AutoQuality -
FullQuality
Values
pub fn allowing(
body: OverwriteBody,
allow: permissions.Permissions,
) -> OverwriteBody
The complete allowed set, not an addition to what is already there.
pub fn create_channel(name: String) -> CreateChannel
pub fn create_channel_body(payload: CreateChannel) -> body.Body
pub fn create_thread(
name: String,
type_: ThreadType,
) -> CreateThread
pub fn create_thread_body(payload: CreateThread) -> body.Body
pub fn create_thread_from_message(
name: String,
) -> CreateThreadFromMessage
pub fn create_thread_from_message_body(
payload: CreateThreadFromMessage,
) -> body.Body
pub fn denying(
body: OverwriteBody,
deny: permissions.Permissions,
) -> OverwriteBody
The complete denied set. Anything in neither set is inherited.
pub fn edit_guild_channel() -> EditGuildChannel
pub fn edit_guild_channel_body(
payload: EditGuildChannel,
) -> body.Body
pub fn edit_thread() -> EditThread
pub fn edit_thread_body(payload: EditThread) -> body.Body
pub fn edits_name_or_topic(payload: EditGuildChannel) -> Bool
Whether this edit touches name or topic. Discord meters those two at
two per ten minutes and says nothing about it in the headers, so
api/channel.edit_channel asks for the answer and the payload is what
holds it. Clearing the topic counts: it is still a topic edit.
pub fn member_overwrite(user: id.Id(id.User)) -> OverwriteBody
pub fn overwrite_body_to_json(
payload: OverwriteBody,
) -> json.Json
An entry in a permission_overwrites array, id included.
pub fn overwrite_from(
overwrite: channel.PermissionOverwrite,
) -> Result(OverwriteBody, Int)
An overwrite read off a channel, ready to send back.
permission_overwrites replaces the whole array, so an edit that changes
one entry has to send the others back with it, and they arrive as
model/channel.PermissionOverwrite.
Error carries the number Discord sent for a type this build does not
know: echoing it back would tell Discord the id means something else.
pub fn overwrite_id(body: OverwriteBody) -> id.Id(id.Overwrite)
The id for the path of PUT /channels/{c}/permissions/{o}, so the path and
the body come from the same value.
pub fn overwrite_permissions_body(
payload: OverwriteBody,
) -> body.Body
PUT /channels/{c}/permissions/{o}, which carries the id in the path
instead. Replaces the whole overwrite.
pub fn role_overwrite(role: id.Id(id.Role)) -> OverwriteBody