Skip to content

Commit

Permalink
discordgo: fix button message component emoji errors (#1598)
Browse files Browse the repository at this point in the history
* discordgo: fix button message component emoji errors

Change discordgo.Button.Emoji to *discordgo.ComponentEmoji and include
the omitempty tag.

Discord no longer allows the `emojis` field in button objects to be
null, and instead require it be absent. This commit adds the "omitempty"
tag to the Emoji field, and changes the value to a pointer.

See also the suggested fix from the Discord Gophers server:
https://discord.com/channels/118456055842734083/155361364909621248/1192299819012722748

* fixup! discordgo: fix button message component emoji errors
  • Loading branch information
galen8183 authored Jan 4, 2024
1 parent 5fd5abb commit 0640e56
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion common/templates/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ func (c *Context) SendResponse(content string) (*discordgo.Message, error) {
discordgo.Button{
Label: "Show Server Info",
Style: discordgo.PrimaryButton,
Emoji: discordgo.ComponentEmoji{Name: "📬"},
Emoji: &discordgo.ComponentEmoji{Name: "📬"},
CustomID: fmt.Sprintf("DM_%d", c.GS.ID),
},
},
Expand Down
4 changes: 2 additions & 2 deletions common/templates/context_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (c *Context) tmplSendDM(s ...interface{}) string {
discordgo.Button{
Label: "Show Server Info",
Style: discordgo.PrimaryButton,
Emoji: discordgo.ComponentEmoji{Name: "📬"},
Emoji: &discordgo.ComponentEmoji{Name: "📬"},
CustomID: fmt.Sprintf("DM_%d", c.GS.ID),
},
},
Expand Down Expand Up @@ -368,7 +368,7 @@ func (c *Context) tmplSendMessage(filterSpecialMentions bool, returnID bool) fun
discordgo.Button{
Label: "Show Server Info",
Style: discordgo.PrimaryButton,
Emoji: discordgo.ComponentEmoji{Name: "📬"},
Emoji: &discordgo.ComponentEmoji{Name: "📬"},
CustomID: fmt.Sprintf("DM_%d", c.GS.ID),
},
},
Expand Down
12 changes: 6 additions & 6 deletions lib/cardsagainstdiscord/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,17 @@ func GetCommonCahButtons() []discordgo.MessageComponent {
discordgo.ActionsRow{
Components: []discordgo.MessageComponent{
discordgo.Button{
Emoji: discordgo.ComponentEmoji{Name: JoinEmoji},
Emoji: &discordgo.ComponentEmoji{Name: JoinEmoji},
Style: discordgo.SuccessButton,
CustomID: CahGameJoined,
},
discordgo.Button{
Emoji: discordgo.ComponentEmoji{Name: LeaveEmoji},
Emoji: &discordgo.ComponentEmoji{Name: LeaveEmoji},
Style: discordgo.DangerButton,
CustomID: CahGameLeft,
},
discordgo.Button{
Emoji: discordgo.ComponentEmoji{Name: PlayPauseEmoji},
Emoji: &discordgo.ComponentEmoji{Name: PlayPauseEmoji},
Style: discordgo.PrimaryButton,
CustomID: CahGamePlayPause,
},
Expand Down Expand Up @@ -823,17 +823,17 @@ func (g *Game) presentPickedResponseCards(edit bool) {
discordgo.ActionsRow{
Components: []discordgo.MessageComponent{
discordgo.Button{
Emoji: discordgo.ComponentEmoji{Name: JoinEmoji},
Emoji: &discordgo.ComponentEmoji{Name: JoinEmoji},
Style: discordgo.SuccessButton,
CustomID: CahGameJoined,
},
discordgo.Button{
Emoji: discordgo.ComponentEmoji{Name: LeaveEmoji},
Emoji: &discordgo.ComponentEmoji{Name: LeaveEmoji},
Style: discordgo.DangerButton,
CustomID: CahGameLeft,
},
discordgo.Button{
Emoji: discordgo.ComponentEmoji{Name: PlayPauseEmoji},
Emoji: &discordgo.ComponentEmoji{Name: PlayPauseEmoji},
Style: discordgo.PrimaryButton,
CustomID: CahGamePlayPause,
},
Expand Down
8 changes: 4 additions & 4 deletions lib/discordgo/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ type ComponentEmoji struct {

// Button represents button component.
type Button struct {
Label string `json:"label"`
Style ButtonStyle `json:"style"`
Disabled bool `json:"disabled"`
Emoji ComponentEmoji `json:"emoji"`
Label string `json:"label"`
Style ButtonStyle `json:"style"`
Disabled bool `json:"disabled"`
Emoji *ComponentEmoji `json:"emoji,omitempty"`

// NOTE: Only button with LinkButton style can have link. Also, URL is mutually exclusive with CustomID.
URL string `json:"url,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion notifications/plugin_bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func sendTemplate(gs *dstate.GuildSet, cs *dstate.ChannelState, tmpl string, ms
discordgo.Button{
Label: "Show Server Info",
Style: discordgo.PrimaryButton,
Emoji: discordgo.ComponentEmoji{Name: "📬"},
Emoji: &discordgo.ComponentEmoji{Name: "📬"},
CustomID: fmt.Sprintf("DM_%d", gs.ID),
},
},
Expand Down

0 comments on commit 0640e56

Please sign in to comment.