diff --git a/examples/slash_commands/main.go b/examples/slash_commands/main.go index 64e37bfc6..1cb3dead0 100644 --- a/examples/slash_commands/main.go +++ b/examples/slash_commands/main.go @@ -76,7 +76,12 @@ var ( Type: discordgo.ApplicationCommandOptionChannel, Name: "channel-option", Description: "Channel option", - Required: false, + // Channel type mask + ChannelTypes: []discordgo.ChannelType{ + discordgo.ChannelTypeGuildText, + discordgo.ChannelTypeGuildVoice, + }, + Required: false, }, { Type: discordgo.ApplicationCommandOptionUser, diff --git a/interactions.go b/interactions.go index 9764e2b1a..c951b19de 100644 --- a/interactions.go +++ b/interactions.go @@ -89,12 +89,10 @@ type ApplicationCommandOption struct { // NOTE: This feature was on the API, but at some point developers decided to remove it. // So I commented it, until it will be officially on the docs. // Default bool `json:"default"` - Required bool `json:"required"` - Options []*ApplicationCommandOption `json:"options"` - - // NOTE: mutually exclusive with Choices. - Autocomplete bool `json:"autocomplete"` + Required bool `json:"required"` Choices []*ApplicationCommandOptionChoice `json:"choices"` + Options []*ApplicationCommandOption `json:"options"` + ChannelTypes []ChannelType `json:"channel_types"` } // ApplicationCommandOptionChoice represents a slash command option choice. diff --git a/message.go b/message.go index fdcdd87d2..91a00db58 100644 --- a/message.go +++ b/message.go @@ -85,8 +85,7 @@ type Message struct { // A list of components attached to the message. Components []MessageComponent `json:"-"` - // A list of embeds present in the message. Multiple - // embeds can currently only be sent by webhooks. + // A list of embeds present in the message. Embeds []*MessageEmbed `json:"embeds"` // A list of users mentioned in the message. @@ -192,7 +191,7 @@ type File struct { // MessageSend stores all parameters you can send with ChannelMessageSendComplex. type MessageSend struct { Content string `json:"content,omitempty"` - Embed *MessageEmbed `json:"embed,omitempty"` + Embeds []*MessageEmbed `json:"embeds,omitempty"` TTS bool `json:"tts"` Components []MessageComponent `json:"components"` Files []*File `json:"-"` @@ -201,6 +200,9 @@ type MessageSend struct { // TODO: Remove this when compatibility is not required. File *File `json:"-"` + + // TODO: Remove this when compatibility is not required. + Embed *MessageEmbed `json:"-"` } // MessageEdit is used to chain parameters via ChannelMessageEditComplex, which @@ -208,11 +210,14 @@ type MessageSend struct { type MessageEdit struct { Content *string `json:"content,omitempty"` Components []MessageComponent `json:"components"` - Embed *MessageEmbed `json:"embed,omitempty"` + Embeds []*MessageEmbed `json:"embeds,omitempty"` AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"` ID string Channel string + + // TODO: Remove this when compatibility is not required. + Embed *MessageEmbed `json:"-"` } // NewMessageEdit returns a MessageEdit struct, initialized @@ -234,7 +239,14 @@ func (m *MessageEdit) SetContent(str string) *MessageEdit { // SetEmbed is a convenience function for setting the embed, // so you can chain commands. func (m *MessageEdit) SetEmbed(embed *MessageEmbed) *MessageEdit { - m.Embed = embed + m.Embeds = []*MessageEmbed{embed} + return m +} + +// SetEmbeds is a convenience function for setting the embeds, +// so you can chain commands. +func (m *MessageEdit) SetEmbeds(embeds []*MessageEmbed) *MessageEdit { + m.Embeds = embeds return m } diff --git a/restapi.go b/restapi.go index a6a609e1d..e3817d233 100644 --- a/restapi.go +++ b/restapi.go @@ -1552,10 +1552,21 @@ var quoteEscaper = strings.NewReplacer("\\", "\\\\", `"`, "\\\"") // channelID : The ID of a Channel. // data : The message struct to send. func (s *Session) ChannelMessageSendComplex(channelID string, data *MessageSend) (st *Message, err error) { - if data.Embed != nil && data.Embed.Type == "" { - data.Embed.Type = "rich" + // TODO: Remove this when compatibility is not required. + if data.Embed != nil { + if data.Embeds == nil { + data.Embeds = []*MessageEmbed{data.Embed} + } else { + err = fmt.Errorf("cannot specify both Embed and Embeds") + return + } } + for _, embed := range data.Embeds { + if embed.Type == "" { + embed.Type = "rich" + } + } endpoint := EndpointChannelMessages(channelID) // TODO: Remove this when compatibility is not required. @@ -1602,8 +1613,15 @@ func (s *Session) ChannelMessageSendTTS(channelID string, content string) (*Mess // channelID : The ID of a Channel. // embed : The embed data to send. func (s *Session) ChannelMessageSendEmbed(channelID string, embed *MessageEmbed) (*Message, error) { + return s.ChannelMessageSendEmbeds(channelID, []*MessageEmbed{embed}) +} + +// ChannelMessageSendEmbeds sends a message to the given channel with multiple embedded data. +// channelID : The ID of a Channel. +// embeds : The embeds data to send. +func (s *Session) ChannelMessageSendEmbeds(channelID string, embeds []*MessageEmbed) (*Message, error) { return s.ChannelMessageSendComplex(channelID, &MessageSend{ - Embed: embed, + Embeds: embeds, }) } @@ -1633,10 +1651,21 @@ func (s *Session) ChannelMessageEdit(channelID, messageID, content string) (*Mes // ChannelMessageEditComplex edits an existing message, replacing it entirely with // the given MessageEdit struct func (s *Session) ChannelMessageEditComplex(m *MessageEdit) (st *Message, err error) { - if m.Embed != nil && m.Embed.Type == "" { - m.Embed.Type = "rich" + // TODO: Remove this when compatibility is not required. + if m.Embed != nil { + if m.Embeds == nil { + m.Embeds = []*MessageEmbed{m.Embed} + } else { + err = fmt.Errorf("cannot specify both Embed and Embeds") + return + } } + for _, embed := range m.Embeds { + if embed.Type == "" { + embed.Type = "rich" + } + } response, err := s.RequestWithBucketID("PATCH", EndpointChannelMessage(m.Channel, m.ID), m, EndpointChannelMessage(m.Channel, "")) if err != nil { return @@ -1651,7 +1680,15 @@ func (s *Session) ChannelMessageEditComplex(m *MessageEdit) (st *Message, err er // messageID : The ID of a Message // embed : The embed data to send func (s *Session) ChannelMessageEditEmbed(channelID, messageID string, embed *MessageEmbed) (*Message, error) { - return s.ChannelMessageEditComplex(NewMessageEdit(channelID, messageID).SetEmbed(embed)) + return s.ChannelMessageEditEmbeds(channelID, messageID, []*MessageEmbed{embed}) +} + +// ChannelMessageEditEmbeds edits an existing message with multiple embedded data. +// channelID : The ID of a Channel +// messageID : The ID of a Message +// embeds : The embeds data to send +func (s *Session) ChannelMessageEditEmbeds(channelID, messageID string, embeds []*MessageEmbed) (*Message, error) { + return s.ChannelMessageEditComplex(NewMessageEdit(channelID, messageID).SetEmbeds(embeds)) } // ChannelMessageDelete deletes a message from the Channel.