Skip to content

Commit

Permalink
Use MessageFlags in InteractionResponseData and WebhookParams (#1178)
Browse files Browse the repository at this point in the history
  • Loading branch information
andresperezl authored and FedorLap2006 committed May 22, 2022
1 parent e455362 commit d7b4a48
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
20 changes: 10 additions & 10 deletions examples/components/main.go
Expand Up @@ -40,7 +40,7 @@ var (
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Huh. I see, maybe some of these resources might help you?",
Flags: 1 << 6,
Flags: discordgo.MessageFlagsEphemeral,
Components: []discordgo.MessageComponent{
discordgo.ActionsRow{
Components: []discordgo.MessageComponent{
Expand Down Expand Up @@ -83,7 +83,7 @@ var (
Data: &discordgo.InteractionResponseData{
Content: "Great! If you wanna know more or just have questions, feel free to visit Discord Devs and Discord Gophers server. " +
"But now, when you know how buttons work, let's move onto select menus (execute `/selects single`)",
Flags: 1 << 6,
Flags: discordgo.MessageFlagsEphemeral,
Components: []discordgo.MessageComponent{
discordgo.ActionsRow{
Components: []discordgo.MessageComponent{
Expand Down Expand Up @@ -122,15 +122,15 @@ var (
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "This is the way.",
Flags: 1 << 6,
Flags: discordgo.MessageFlagsEphemeral,
},
}
default:
response = &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "It is not the way to go.",
Flags: 1 << 6,
Flags: discordgo.MessageFlagsEphemeral,
},
}
}
Expand All @@ -142,7 +142,7 @@ var (
_, err = s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{
Content: "Anyways, now when you know how to use single select menus, let's see how multi select menus work. " +
"Try calling `/selects multi` command.",
Flags: 1 << 6,
Flags: discordgo.MessageFlagsEphemeral,
})
if err != nil {
panic(err)
Expand All @@ -157,7 +157,7 @@ var (
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Here is your stackoverflow URL: " + fmt.Sprintf(stackoverflowFormat, strings.Join(data.Values, "+")),
Flags: 1 << 6,
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
Expand Down Expand Up @@ -196,7 +196,7 @@ var (
},
},
},
Flags: 1 << 6,
Flags: discordgo.MessageFlagsEphemeral,
})
if err != nil {
panic(err)
Expand All @@ -209,7 +209,7 @@ var (
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Are you comfortable with buttons and other message components?",
Flags: 1 << 6,
Flags: discordgo.MessageFlagsEphemeral,
// Buttons and other components are specified in Components field.
Components: []discordgo.MessageComponent{
// ActionRow is a container of all buttons within the same row.
Expand Down Expand Up @@ -269,7 +269,7 @@ var (
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Now let's take a look on selects. This is single item select menu.",
Flags: 1 << 6,
Flags: discordgo.MessageFlagsEphemeral,
Components: []discordgo.MessageComponent{
discordgo.ActionsRow{
Components: []discordgo.MessageComponent{
Expand Down Expand Up @@ -320,7 +320,7 @@ var (
Data: &discordgo.InteractionResponseData{
Content: "The tastiest things are left for the end. Let's see how the multi-item select menu works: " +
"try generating your own stackoverflow search link",
Flags: 1 << 6,
Flags: discordgo.MessageFlagsEphemeral,
Components: []discordgo.MessageComponent{
discordgo.ActionsRow{
Components: []discordgo.MessageComponent{
Expand Down
14 changes: 7 additions & 7 deletions examples/context_menus/main.go
Expand Up @@ -74,7 +74,7 @@ var (
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Operation rickroll has begun",
Flags: 1 << 6,
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
Expand All @@ -87,7 +87,7 @@ var (
if err != nil {
_, err = s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{
Content: fmt.Sprintf("Mission failed. Cannot send a message to this user: %q", err.Error()),
Flags: 1 << 6,
Flags: discordgo.MessageFlagsEphemeral,
})
if err != nil {
panic(err)
Expand All @@ -108,7 +108,7 @@ var (
Content: searchLink(
i.ApplicationCommandData().Resolved.Messages[i.ApplicationCommandData().TargetID].Content,
"https://google.com/search?q=%s", "+"),
Flags: 1 << 6,
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
Expand All @@ -122,7 +122,7 @@ var (
Content: searchLink(
i.ApplicationCommandData().Resolved.Messages[i.ApplicationCommandData().TargetID].Content,
"https://stackoverflow.com/search?q=%s", "+"),
Flags: 1 << 6,
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
Expand All @@ -136,7 +136,7 @@ var (
Content: searchLink(
i.ApplicationCommandData().Resolved.Messages[i.ApplicationCommandData().TargetID].Content,
"https://pkg.go.dev/search?q=%s", "+"),
Flags: 1 << 6,
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
Expand All @@ -150,7 +150,7 @@ var (
Content: searchLink(
i.ApplicationCommandData().Resolved.Messages[i.ApplicationCommandData().TargetID].Content,
"https://discord.js.org/#/docs/main/stable/search?query=%s", "+"),
Flags: 1 << 6,
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
Expand All @@ -164,7 +164,7 @@ var (
Content: searchLink(
i.ApplicationCommandData().Resolved.Messages[i.ApplicationCommandData().TargetID].Content,
"https://discordpy.readthedocs.io/en/stable/search.html?q=%s", "+"),
Flags: 1 << 6,
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion examples/modals/main.go
Expand Up @@ -99,7 +99,7 @@ func main() {
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Thank you for taking your time to fill this survey",
Flags: 1 << 6,
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion examples/slash_commands/main.go
Expand Up @@ -503,7 +503,7 @@ var (
// Note: this isn't documented, but you can use that if you want to.
// This flag just allows you to create messages visible only for the caller of the command
// (user who triggered the command)
Flags: 1 << 6,
Flags: discordgo.MessageFlagsEphemeral,
Content: "Surprise!",
},
})
Expand Down
4 changes: 3 additions & 1 deletion interactions.go
Expand Up @@ -534,9 +534,11 @@ type InteractionResponseData struct {
Components []MessageComponent `json:"components"`
Embeds []*MessageEmbed `json:"embeds"`
AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"`
Flags uint64 `json:"flags,omitempty"`
Files []*File `json:"-"`

// NOTE: only MessageFlagsSuppressEmbeds and MessageFlagsEphemeral can be set.
Flags MessageFlags `json:"flags,omitempty"`

// NOTE: autocomplete interaction only.
Choices []*ApplicationCommandOptionChoice `json:"choices,omitempty"`

Expand Down
5 changes: 3 additions & 2 deletions webhook.go
Expand Up @@ -35,8 +35,9 @@ type WebhookParams struct {
Components []MessageComponent `json:"components"`
Embeds []*MessageEmbed `json:"embeds,omitempty"`
AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"`
// NOTE: Works only for followup messages.
Flags uint64 `json:"flags,omitempty"`
// Only MessageFlagsSuppressEmbeds and MessageFlagsEphemeral can be set.
// MessageFlagsEphemeral can only be set when using Followup Message Create endpoint.
Flags MessageFlags `json:"flags,omitempty"`
}

// WebhookEdit stores data for editing of a webhook message.
Expand Down

0 comments on commit d7b4a48

Please sign in to comment.