Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Components Support #956

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 14 additions & 4 deletions interactions.go
Expand Up @@ -65,6 +65,7 @@ type InteractionType uint8
const (
InteractionPing InteractionType = 1
InteractionApplicationCommand InteractionType = 2
InteractionMessageComponent InteractionType = 3
)

// Interaction represents an interaction event created via a slash command.
Expand All @@ -85,17 +86,21 @@ type Interaction struct {
// if it was invoked in a guild, the `Member` field will be filled instead.
// Make sure to check for `nil` before using this field.
User *User `json:"user"`
// For components, the message they were attached to
Message *Message `json:"message"`

Token string `json:"token"`
Version int `json:"version"`
}

// ApplicationCommandInteractionData contains data received in an interaction event.
type ApplicationCommandInteractionData struct {
ID string `json:"id"`
Name string `json:"name"`
Resolved *ApplicationCommandInteractionDataResolved `json:"resolved"`
Options []*ApplicationCommandInteractionDataOption `json:"options"`
ID string `json:"id"`
Name string `json:"name"`
Resolved *ApplicationCommandInteractionDataResolved `json:"resolved"`
Options []*ApplicationCommandInteractionDataOption `json:"options"`
CustomID string `json:"custom_id"` // for components, the custom_id of the component
ComponentType MessageComponentType `json:"component_type"` // for components, the type of the component
}

// ApplicationCommandInteractionDataResolved contains resolved data for command arguments.
Expand Down Expand Up @@ -243,6 +248,10 @@ const (
InteractionResponseChannelMessageWithSource InteractionResponseType = 4
// InteractionResponseDeferredChannelMessageWithSource acknowledges that the event was received, and that a follow-up will come later.
InteractionResponseDeferredChannelMessageWithSource InteractionResponseType = 5
// InteractionResponseDeferredMessageUpdate acknowledges that the message component interaction event was received, and message will be updated later.
InteractionResponseDeferredMessageUpdate InteractionResponseType = 6
// InteractionResponseUpdateMessage is for updating the message to which message component was attached to.
InteractionResponseUpdateMessage InteractionResponseType = 7
)

// InteractionResponse represents a response for an interaction event.
Expand All @@ -256,6 +265,7 @@ type InteractionApplicationCommandResponseData struct {
TTS bool `json:"tts,omitempty"`
Content string `json:"content,omitempty"`
Embeds []*MessageEmbed `json:"embeds,omitempty"`
Components []*MessageComponent `json:"components,omitempty"`
AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"`

// NOTE: Undocumented feature, be careful with it.
Expand Down
34 changes: 34 additions & 0 deletions message.go
Expand Up @@ -90,6 +90,9 @@ type Message struct {
// A list of reactions to the message.
Reactions []*MessageReactions `json:"reactions"`

// A list of message components
Components []*MessageComponent `json:"components"`

// Whether the message is pinned or not.
Pinned bool `json:"pinned"`

Expand Down Expand Up @@ -372,6 +375,37 @@ type MessageApplication struct {
Name string `json:"name"`
}

// MessageComponentType type
type MessageComponentType int

const (
MessageComponentTypeActionRow MessageComponentType = 1
MessageComponentTypeButton MessageComponentType = 2
)

// MessageComponentButtonStyle style
type MessageComponentButtonStyle int

const (
MessageComponentButtonStylePrimary = 1
MessageComponentButtonStyleSecondary = 2
MessageComponentButtonStyleSuccess = 3
MessageComponentButtonStyleDanger = 4
MessageComponentButtonStyleLink = 5
)

// MessageComponent are a framework for adding interactive elements to the messages your app or bot sends.
type MessageComponent struct {
Type MessageComponentType `json:"type"`
Style MessageComponentButtonStyle `json:"style"`
Label string `json:"label"`
Emoji *Emoji `json:"emoji"`
CustomID string `json:"custom_id"`
URL string `json:"url"`
Disabled bool `json:"disabled"`
Components []*MessageComponent `json:"components"`
}

// MessageReference contains reference data sent with crossposted messages
type MessageReference struct {
MessageID string `json:"message_id"`
Expand Down
1 change: 1 addition & 0 deletions webhook.go
Expand Up @@ -41,4 +41,5 @@ type WebhookEdit struct {
Content string `json:"content,omitempty"`
Embeds []*MessageEmbed `json:"embeds,omitempty"`
AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"`
Components []*MessageComponent `json:"components,omitempty"`
}