glyde/payload/interaction
The response to an interaction: POST /interactions/{id}/{token}/callback.
Types 4 and 7 share a JSON shape and not their semantics: 4 creates a message, so an omitted key is unset; 7 edits the message the component sits on, so an omitted key keeps the old value. Hence two types.
Deferring fixes ephemerality for the whole interaction: defer publicly, edit with EPHEMERAL, and the reply leaks into the channel.
Types
Send-only, so no unknown tail.
pub type InteractionResponse {
Pong
ChannelMessageWithSource(MessageCallbackData)
DeferredChannelMessageWithSource(ephemeral: Bool)
DeferredUpdateMessage
UpdateMessage(message.EditMessage)
AutocompleteResult(
choices: List(
application_command.ApplicationCommandOptionChoice,
),
)
}
Constructors
-
PongACK a PING. A gateway bot never sends this; an HTTP-interactions bot that cannot send it can never register its endpoint.
-
ChannelMessageWithSource(MessageCallbackData)Reply with a new message. Create semantics.
-
DeferredChannelMessageWithSource(ephemeral: Bool)“Thinking…”. Turns the three-second budget into fifteen minutes; finish with
PATCH /webhooks/{app}/{token}/messages/@original. EPHEMERAL is the only flag accepted, henceBool. -
DeferredUpdateMessageComponents only. ACK with no loading state, and no data at all.
-
UpdateMessage(message.EditMessage)Components only. Edit semantics:
Present([])takes the components off the message. Field for field and key for key this is a message edit, so it carries the same type, built withpayload/message.edit. -
AutocompleteResult( choices: List( application_command.ApplicationCommandOptionChoice, ), )Autocomplete only. An empty list is legal and means no suggestions. Max 25.
Callback data for ChannelMessageWithSource. Same shape and rules as
CreateMessage.
pub type MessageCallbackData {
MessageCallbackData(
content: option.Option(String),
tts: Bool,
embeds: List(embed.Embed),
components: List(component.Component),
files: List(file.File),
allowed_mentions: option.Option(
allowed_mentions.AllowedMentions,
),
flags: flags.Flags(message.MessageFlag),
)
}
Constructors
-
MessageCallbackData( content: option.Option(String), tts: Bool, embeds: List(embed.Embed), components: List(component.Component), files: List(file.File), allowed_mentions: option.Option( allowed_mentions.AllowedMentions, ), flags: flags.Flags(message.MessageFlag), )Arguments
- allowed_mentions
-
A decision, never a default: leaving it out lets Discord turn every @mention in the content into a real ping.
- flags
-
Only EPHEMERAL, SUPPRESS_EMBEDS, SUPPRESS_NOTIFICATIONS, IS_VOICE_MESSAGE and IS_COMPONENTS_V2 are accepted. Prefer
ephemeralto assembling this by hand.
Values
pub fn callback_type(
response: InteractionResponse,
) -> interaction.InteractionCallbackType
The callback type Discord reads off the envelope. The numbering lives in
model/interaction, which decodes the same values coming back.
pub fn ephemeral(
data: MessageCallbackData,
) -> MessageCallbackData
Only the invoking user sees it.
pub fn message_data() -> MessageCallbackData
pub fn message_data_to_json(
data: MessageCallbackData,
) -> json.Json
pub fn response_body(response: InteractionResponse) -> body.Body
A ready-to-send body for the callback route, files already paired to their
attachments entries.
The callback nests its attachments array under data, so the document is
finished here rather than left open: a top-level array as well would name
the same parts twice, and the copy without the kept ones deletes them.
pub fn response_files(
response: InteractionResponse,
) -> List(file.File)
The files the multipart body has to carry, in files[n] order.
pub fn text(content: String) -> MessageCallbackData
pub fn to_json(response: InteractionResponse) -> json.Json
pub fn update_data(
mentions: allowed_mentions.AllowedMentions,
) -> message.EditMessage
The only constructor: the mention policy is not optional.
pub fn update_data_to_json(
data: message.EditMessage,
) -> json.Json