tadpole/model/channel
The Discord channel object, trimmed to what the first slice reads.
type is reserved in Gleam, so Discord’s key lands as channel_type.
Option fields mean Discord omits or nulls them for some channel
kinds: name and guild_id are None for DMs and group DMs (which
have no name and no guild), and topic is null in most non-text
channels. last_message_id is a pointer to the most recent message
and deliberately a String, not a typed ID: tadpole never
dereferences it, so snowflake validation would only add a failure
mode. channel_type stays Discord’s raw integer (0 GUILD_TEXT,
1 DM, 2 GUILD_VOICE, …) for the same reason message_type does —
Discord adds channel types faster than libraries track them.
Types
pub type Channel {
Channel(
id: ids.ChannelId,
channel_type: Int,
name: option.Option(String),
guild_id: option.Option(ids.GuildId),
topic: option.Option(String),
last_message_id: option.Option(String),
)
}
Constructors
-
Channel( id: ids.ChannelId, channel_type: Int, name: option.Option(String), guild_id: option.Option(ids.GuildId), topic: option.Option(String), last_message_id: option.Option(String), )Arguments
- channel_type
-
Discord’s raw channel type integer: 0 GUILD_TEXT, 1 DM, 2 GUILD_VOICE, and so on. Kept raw for the same reason message types are: Discord adds them faster than libraries track them.
- name
-
None for DMs and group DMs.
- guild_id
-
None for DMs and group DMs, which have no guild to belong to.
- topic
-
The channel topic; null in most non-text channels.
- last_message_id
-
Deliberately String, not a typed ID: it is an informational pointer to the most recent message and is never dereferenced here, so snowflake validation would only add a failure mode.
Values
pub fn decoder() -> decode.Decoder(Channel)
Decoder for Discord’s channel object. Discord sends IDs as strings;
a non-snowflake string in id or guild_id fails the decode.
Unknown fields are ignored.
pub fn from_json(
payload: String,
) -> Result(Channel, error.TadpoleError)
Decode a channel from its JSON payload: the channel object, not a
gateway frame. Fails with error.DecodeFailed when the payload is not
valid JSON or an ID is not a snowflake. The error’s event field
stays None; wiring that knows the event name fills it in.