github.com/meowstercatel/discordgo@v0.0.0-20250615204139-29b43d676735/message.go (about)

     1  // Discordgo - Discord bindings for Go
     2  // Available at https://github.com/bwmarrin/discordgo
     3  
     4  // Copyright 2015-2016 Bruce Marriner <bruce@sqls.net>.  All rights reserved.
     5  // Use of this source code is governed by a BSD-style
     6  // license that can be found in the LICENSE file.
     7  
     8  // This file contains code related to the Message struct
     9  
    10  package discordgo
    11  
    12  import (
    13  	"encoding/json"
    14  	"io"
    15  	"regexp"
    16  	"strings"
    17  	"time"
    18  )
    19  
    20  // MessageType is the type of Message
    21  // https://discord.com/developers/docs/resources/channel#message-object-message-types
    22  type MessageType int
    23  
    24  // Block contains the valid known MessageType values
    25  const (
    26  	MessageTypeDefault                               MessageType = 0
    27  	MessageTypeRecipientAdd                          MessageType = 1
    28  	MessageTypeRecipientRemove                       MessageType = 2
    29  	MessageTypeCall                                  MessageType = 3
    30  	MessageTypeChannelNameChange                     MessageType = 4
    31  	MessageTypeChannelIconChange                     MessageType = 5
    32  	MessageTypeChannelPinnedMessage                  MessageType = 6
    33  	MessageTypeGuildMemberJoin                       MessageType = 7
    34  	MessageTypeUserPremiumGuildSubscription          MessageType = 8
    35  	MessageTypeUserPremiumGuildSubscriptionTierOne   MessageType = 9
    36  	MessageTypeUserPremiumGuildSubscriptionTierTwo   MessageType = 10
    37  	MessageTypeUserPremiumGuildSubscriptionTierThree MessageType = 11
    38  	MessageTypeChannelFollowAdd                      MessageType = 12
    39  	MessageTypeGuildDiscoveryDisqualified            MessageType = 14
    40  	MessageTypeGuildDiscoveryRequalified             MessageType = 15
    41  	MessageTypeThreadCreated                         MessageType = 18
    42  	MessageTypeReply                                 MessageType = 19
    43  	MessageTypeChatInputCommand                      MessageType = 20
    44  	MessageTypeThreadStarterMessage                  MessageType = 21
    45  	MessageTypeContextMenuCommand                    MessageType = 23
    46  )
    47  
    48  // A Message stores all data related to a specific Discord message.
    49  type Message struct {
    50  	// The ID of the message.
    51  	ID string `json:"id"`
    52  
    53  	// The ID of the channel in which the message was sent.
    54  	ChannelID string `json:"channel_id"`
    55  
    56  	// The ID of the guild in which the message was sent.
    57  	GuildID string `json:"guild_id,omitempty"`
    58  
    59  	// The content of the message.
    60  	Content string `json:"content"`
    61  
    62  	// The time at which the messsage was sent.
    63  	// CAUTION: this field may be removed in a
    64  	// future API version; it is safer to calculate
    65  	// the creation time via the ID.
    66  	Timestamp time.Time `json:"timestamp"`
    67  
    68  	// The time at which the last edit of the message
    69  	// occurred, if it has been edited.
    70  	EditedTimestamp *time.Time `json:"edited_timestamp"`
    71  
    72  	// The roles mentioned in the message.
    73  	MentionRoles []string `json:"mention_roles"`
    74  
    75  	// Whether the message is text-to-speech.
    76  	TTS bool `json:"tts"`
    77  
    78  	// Whether the message mentions everyone.
    79  	MentionEveryone bool `json:"mention_everyone"`
    80  
    81  	// The author of the message. This is not guaranteed to be a
    82  	// valid user (webhook-sent messages do not possess a full author).
    83  	Author *User `json:"author"`
    84  
    85  	// A list of attachments present in the message.
    86  	Attachments []*MessageAttachment `json:"attachments"`
    87  
    88  	// A list of components attached to the message.
    89  	Components []MessageComponent `json:"-"`
    90  
    91  	// A list of embeds present in the message.
    92  	Embeds []*MessageEmbed `json:"embeds"`
    93  
    94  	// A list of users mentioned in the message.
    95  	Mentions []*User `json:"mentions"`
    96  
    97  	// A list of reactions to the message.
    98  	Reactions []*MessageReactions `json:"reactions"`
    99  
   100  	// Whether the message is pinned or not.
   101  	Pinned bool `json:"pinned"`
   102  
   103  	// The type of the message.
   104  	Type MessageType `json:"type"`
   105  
   106  	// The webhook ID of the message, if it was generated by a webhook
   107  	WebhookID string `json:"webhook_id"`
   108  
   109  	// Member properties for this message's author,
   110  	// contains only partial information
   111  	Member *Member `json:"member"`
   112  
   113  	// Channels specifically mentioned in this message
   114  	// Not all channel mentions in a message will appear in mention_channels.
   115  	// Only textual channels that are visible to everyone in a lurkable guild will ever be included.
   116  	// Only crossposted messages (via Channel Following) currently include mention_channels at all.
   117  	// If no mentions in the message meet these requirements, this field will not be sent.
   118  	MentionChannels []*Channel `json:"mention_channels"`
   119  
   120  	// Is sent with Rich Presence-related chat embeds
   121  	Activity *MessageActivity `json:"activity"`
   122  
   123  	// Is sent with Rich Presence-related chat embeds
   124  	Application *MessageApplication `json:"application"`
   125  
   126  	// MessageReference contains reference data sent with crossposted or reply messages.
   127  	// This does not contain the reference *to* this message; this is for when *this* message references another.
   128  	// To generate a reference to this message, use (*Message).Reference().
   129  	MessageReference *MessageReference `json:"message_reference"`
   130  
   131  	// The message associated with the message_reference
   132  	// NOTE: This field is only returned for messages with a type of 19 (REPLY) or 21 (THREAD_STARTER_MESSAGE).
   133  	// If the message is a reply but the referenced_message field is not present,
   134  	// the backend did not attempt to fetch the message that was being replied to, so its state is unknown.
   135  	// If the field exists but is null, the referenced message was deleted.
   136  	ReferencedMessage *Message `json:"referenced_message"`
   137  
   138  	// The message associated with the message_reference.
   139  	// This is a minimal subset of fields in a message (e.g. Author is excluded)
   140  	// NOTE: This field is only returned when referenced when MessageReference.Type is MessageReferenceTypeForward.
   141  	MessageSnapshots []MessageSnapshot `json:"message_snapshots"`
   142  
   143  	// Deprecated, use InteractionMetadata.
   144  	// Is sent when the message is a response to an Interaction, without an existing message.
   145  	// This means responses to message component interactions do not include this property,
   146  	// instead including a MessageReference, as components exist on preexisting messages.
   147  	Interaction *MessageInteraction `json:"interaction"`
   148  
   149  	InteractionMetadata *MessageInteractionMetadata `json:"interaction_metadata"`
   150  
   151  	// The flags of the message, which describe extra features of a message.
   152  	// This is a combination of bit masks; the presence of a certain permission can
   153  	// be checked by performing a bitwise AND between this int and the flag.
   154  	Flags MessageFlags `json:"flags"`
   155  
   156  	// The thread that was started from this message, includes thread member object
   157  	Thread *Channel `json:"thread,omitempty"`
   158  
   159  	// An array of StickerItem objects, representing sent stickers, if there were any.
   160  	StickerItems []*StickerItem `json:"sticker_items"`
   161  
   162  	// A poll object.
   163  	Poll *Poll `json:"poll"`
   164  }
   165  
   166  // UnmarshalJSON is a helper function to unmarshal the Message.
   167  func (m *Message) UnmarshalJSON(data []byte) error {
   168  	type message Message
   169  	var v struct {
   170  		message
   171  		RawComponents []unmarshalableMessageComponent `json:"components"`
   172  	}
   173  	err := json.Unmarshal(data, &v)
   174  	if err != nil {
   175  		return err
   176  	}
   177  	*m = Message(v.message)
   178  	m.Components = make([]MessageComponent, len(v.RawComponents))
   179  	for i, v := range v.RawComponents {
   180  		m.Components[i] = v.MessageComponent
   181  	}
   182  	return err
   183  }
   184  
   185  // GetCustomEmojis pulls out all the custom (Non-unicode) emojis from a message and returns a Slice of the Emoji struct.
   186  func (m *Message) GetCustomEmojis() []*Emoji {
   187  	var toReturn []*Emoji
   188  	emojis := EmojiRegex.FindAllString(m.Content, -1)
   189  	if len(emojis) < 1 {
   190  		return toReturn
   191  	}
   192  	for _, em := range emojis {
   193  		parts := strings.Split(em, ":")
   194  		toReturn = append(toReturn, &Emoji{
   195  			ID:       parts[2][:len(parts[2])-1],
   196  			Name:     parts[1],
   197  			Animated: strings.HasPrefix(em, "<a:"),
   198  		})
   199  	}
   200  	return toReturn
   201  }
   202  
   203  // MessageFlags is the flags of "message" (see MessageFlags* consts)
   204  // https://discord.com/developers/docs/resources/channel#message-object-message-flags
   205  type MessageFlags int
   206  
   207  // Valid MessageFlags values
   208  const (
   209  	// MessageFlagsCrossPosted This message has been published to subscribed channels (via Channel Following).
   210  	MessageFlagsCrossPosted MessageFlags = 1 << 0
   211  	// MessageFlagsIsCrossPosted this message originated from a message in another channel (via Channel Following).
   212  	MessageFlagsIsCrossPosted MessageFlags = 1 << 1
   213  	// MessageFlagsSuppressEmbeds do not include any embeds when serializing this message.
   214  	MessageFlagsSuppressEmbeds MessageFlags = 1 << 2
   215  	// TODO: deprecated, remove when compatibility is not needed
   216  	MessageFlagsSupressEmbeds MessageFlags = 1 << 2
   217  	// MessageFlagsSourceMessageDeleted the source message for this crosspost has been deleted (via Channel Following).
   218  	MessageFlagsSourceMessageDeleted MessageFlags = 1 << 3
   219  	// MessageFlagsUrgent this message came from the urgent message system.
   220  	MessageFlagsUrgent MessageFlags = 1 << 4
   221  	// MessageFlagsHasThread this message has an associated thread, with the same id as the message.
   222  	MessageFlagsHasThread MessageFlags = 1 << 5
   223  	// MessageFlagsEphemeral this message is only visible to the user who invoked the Interaction.
   224  	MessageFlagsEphemeral MessageFlags = 1 << 6
   225  	// MessageFlagsLoading this message is an Interaction Response and the bot is "thinking".
   226  	MessageFlagsLoading MessageFlags = 1 << 7
   227  	// MessageFlagsFailedToMentionSomeRolesInThread this message failed to mention some roles and add their members to the thread.
   228  	MessageFlagsFailedToMentionSomeRolesInThread MessageFlags = 1 << 8
   229  	// MessageFlagsSuppressNotifications this message will not trigger push and desktop notifications.
   230  	MessageFlagsSuppressNotifications MessageFlags = 1 << 12
   231  	// MessageFlagsIsVoiceMessage this message is a voice message.
   232  	MessageFlagsIsVoiceMessage MessageFlags = 1 << 13
   233  	// MessageFlagsIsComponentsV2 this message uses the new components system. Disables the ability of sending `content` & `embeds`
   234  	MessageFlagsIsComponentsV2 MessageFlags = 1 << 15
   235  )
   236  
   237  // File stores info about files you e.g. send in messages.
   238  type File struct {
   239  	Name        string
   240  	ContentType string
   241  	Reader      io.Reader
   242  }
   243  
   244  // MessageSend stores all parameters you can send with ChannelMessageSendComplex.
   245  type MessageSend struct {
   246  	Content         string                  `json:"content,omitempty"`
   247  	Embeds          []*MessageEmbed         `json:"embeds"`
   248  	TTS             bool                    `json:"tts"`
   249  	Components      []MessageComponent      `json:"components"`
   250  	Files           []*File                 `json:"-"`
   251  	AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"`
   252  	Reference       *MessageReference       `json:"message_reference,omitempty"`
   253  	StickerIDs      []string                `json:"sticker_ids"`
   254  	Flags           MessageFlags            `json:"flags,omitempty"`
   255  	Poll            *Poll                   `json:"poll,omitempty"`
   256  
   257  	// TODO: Remove this when compatibility is not required.
   258  	File *File `json:"-"`
   259  
   260  	// TODO: Remove this when compatibility is not required.
   261  	Embed *MessageEmbed `json:"-"`
   262  }
   263  
   264  // MessageEdit is used to chain parameters via ChannelMessageEditComplex, which
   265  // is also where you should get the instance from.
   266  type MessageEdit struct {
   267  	Content         *string                 `json:"content,omitempty"`
   268  	Components      *[]MessageComponent     `json:"components,omitempty"`
   269  	Embeds          *[]*MessageEmbed        `json:"embeds,omitempty"`
   270  	AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"`
   271  	Flags           MessageFlags            `json:"flags,omitempty"`
   272  	// Files to append to the message
   273  	Files []*File `json:"-"`
   274  	// Overwrite existing attachments
   275  	Attachments *[]*MessageAttachment `json:"attachments,omitempty"`
   276  
   277  	ID      string
   278  	Channel string
   279  
   280  	// TODO: Remove this when compatibility is not required.
   281  	Embed *MessageEmbed `json:"-"`
   282  }
   283  
   284  // NewMessageEdit returns a MessageEdit struct, initialized
   285  // with the Channel and ID.
   286  func NewMessageEdit(channelID string, messageID string) *MessageEdit {
   287  	return &MessageEdit{
   288  		Channel: channelID,
   289  		ID:      messageID,
   290  	}
   291  }
   292  
   293  // SetContent is the same as setting the variable Content,
   294  // except it doesn't take a pointer.
   295  func (m *MessageEdit) SetContent(str string) *MessageEdit {
   296  	m.Content = &str
   297  	return m
   298  }
   299  
   300  // SetEmbed is a convenience function for setting the embed,
   301  // so you can chain commands.
   302  func (m *MessageEdit) SetEmbed(embed *MessageEmbed) *MessageEdit {
   303  	m.Embeds = &[]*MessageEmbed{embed}
   304  	return m
   305  }
   306  
   307  // SetEmbeds is a convenience function for setting the embeds,
   308  // so you can chain commands.
   309  func (m *MessageEdit) SetEmbeds(embeds []*MessageEmbed) *MessageEdit {
   310  	m.Embeds = &embeds
   311  	return m
   312  }
   313  
   314  // AllowedMentionType describes the types of mentions used
   315  // in the MessageAllowedMentions type.
   316  type AllowedMentionType string
   317  
   318  // The types of mentions used in MessageAllowedMentions.
   319  const (
   320  	AllowedMentionTypeRoles    AllowedMentionType = "roles"
   321  	AllowedMentionTypeUsers    AllowedMentionType = "users"
   322  	AllowedMentionTypeEveryone AllowedMentionType = "everyone"
   323  )
   324  
   325  // MessageAllowedMentions allows the user to specify which mentions
   326  // Discord is allowed to parse in this message. This is useful when
   327  // sending user input as a message, as it prevents unwanted mentions.
   328  // If this type is used, all mentions must be explicitly whitelisted,
   329  // either by putting an AllowedMentionType in the Parse slice
   330  // (allowing all mentions of that type) or, in the case of roles and
   331  // users, explicitly allowing those mentions on an ID-by-ID basis.
   332  // For more information on this functionality, see:
   333  // https://discordapp.com/developers/docs/resources/channel#allowed-mentions-object-allowed-mentions-reference
   334  type MessageAllowedMentions struct {
   335  	// The mention types that are allowed to be parsed in this message.
   336  	// Please note that this is purposely **not** marked as omitempty,
   337  	// so if a zero-value MessageAllowedMentions object is provided no
   338  	// mentions will be allowed.
   339  	Parse []AllowedMentionType `json:"parse"`
   340  
   341  	// A list of role IDs to allow. This cannot be used when specifying
   342  	// AllowedMentionTypeRoles in the Parse slice.
   343  	Roles []string `json:"roles,omitempty"`
   344  
   345  	// A list of user IDs to allow. This cannot be used when specifying
   346  	// AllowedMentionTypeUsers in the Parse slice.
   347  	Users []string `json:"users,omitempty"`
   348  
   349  	// For replies, whether to mention the author of the message being replied to
   350  	RepliedUser bool `json:"replied_user"`
   351  }
   352  
   353  // A MessageAttachment stores data for message attachments.
   354  type MessageAttachment struct {
   355  	ID           string                 `json:"id"`
   356  	URL          string                 `json:"url"`
   357  	ProxyURL     string                 `json:"proxy_url"`
   358  	Filename     string                 `json:"filename"`
   359  	ContentType  string                 `json:"content_type"`
   360  	Width        int                    `json:"width"`
   361  	Height       int                    `json:"height"`
   362  	Size         int                    `json:"size"`
   363  	Ephemeral    bool                   `json:"ephemeral"`
   364  	DurationSecs float64                `json:"duration_secs"`
   365  	Waveform     string                 `json:"waveform"`
   366  	Flags        MessageAttachmentFlags `json:"flags"`
   367  }
   368  
   369  // MessageAttachmentFlags is the flags of a message attachment.
   370  type MessageAttachmentFlags int
   371  
   372  // Valid MessageAttachmentFlags values.
   373  const (
   374  	MessageAttachmentFlagsIsRemix MessageAttachmentFlags = 1 << 2
   375  )
   376  
   377  // MessageEmbedFooter is a part of a MessageEmbed struct.
   378  type MessageEmbedFooter struct {
   379  	Text         string `json:"text,omitempty"`
   380  	IconURL      string `json:"icon_url,omitempty"`
   381  	ProxyIconURL string `json:"proxy_icon_url,omitempty"`
   382  }
   383  
   384  // MessageEmbedImage is a part of a MessageEmbed struct.
   385  type MessageEmbedImage struct {
   386  	URL      string `json:"url"`
   387  	ProxyURL string `json:"proxy_url,omitempty"`
   388  	Width    int    `json:"width,omitempty"`
   389  	Height   int    `json:"height,omitempty"`
   390  }
   391  
   392  // MessageEmbedThumbnail is a part of a MessageEmbed struct.
   393  type MessageEmbedThumbnail struct {
   394  	URL      string `json:"url"`
   395  	ProxyURL string `json:"proxy_url,omitempty"`
   396  	Width    int    `json:"width,omitempty"`
   397  	Height   int    `json:"height,omitempty"`
   398  }
   399  
   400  // MessageEmbedVideo is a part of a MessageEmbed struct.
   401  type MessageEmbedVideo struct {
   402  	URL    string `json:"url,omitempty"`
   403  	Width  int    `json:"width,omitempty"`
   404  	Height int    `json:"height,omitempty"`
   405  }
   406  
   407  // MessageEmbedProvider is a part of a MessageEmbed struct.
   408  type MessageEmbedProvider struct {
   409  	URL  string `json:"url,omitempty"`
   410  	Name string `json:"name,omitempty"`
   411  }
   412  
   413  // MessageEmbedAuthor is a part of a MessageEmbed struct.
   414  type MessageEmbedAuthor struct {
   415  	URL          string `json:"url,omitempty"`
   416  	Name         string `json:"name"`
   417  	IconURL      string `json:"icon_url,omitempty"`
   418  	ProxyIconURL string `json:"proxy_icon_url,omitempty"`
   419  }
   420  
   421  // MessageEmbedField is a part of a MessageEmbed struct.
   422  type MessageEmbedField struct {
   423  	Name   string `json:"name"`
   424  	Value  string `json:"value"`
   425  	Inline bool   `json:"inline,omitempty"`
   426  }
   427  
   428  // An MessageEmbed stores data for message embeds.
   429  type MessageEmbed struct {
   430  	URL         string                 `json:"url,omitempty"`
   431  	Type        EmbedType              `json:"type,omitempty"`
   432  	Title       string                 `json:"title,omitempty"`
   433  	Description string                 `json:"description,omitempty"`
   434  	Timestamp   string                 `json:"timestamp,omitempty"`
   435  	Color       int                    `json:"color,omitempty"`
   436  	Footer      *MessageEmbedFooter    `json:"footer,omitempty"`
   437  	Image       *MessageEmbedImage     `json:"image,omitempty"`
   438  	Thumbnail   *MessageEmbedThumbnail `json:"thumbnail,omitempty"`
   439  	Video       *MessageEmbedVideo     `json:"video,omitempty"`
   440  	Provider    *MessageEmbedProvider  `json:"provider,omitempty"`
   441  	Author      *MessageEmbedAuthor    `json:"author,omitempty"`
   442  	Fields      []*MessageEmbedField   `json:"fields,omitempty"`
   443  }
   444  
   445  // EmbedType is the type of embed
   446  // https://discord.com/developers/docs/resources/channel#embed-object-embed-types
   447  type EmbedType string
   448  
   449  // Block of valid EmbedTypes
   450  const (
   451  	EmbedTypeRich    EmbedType = "rich"
   452  	EmbedTypeImage   EmbedType = "image"
   453  	EmbedTypeVideo   EmbedType = "video"
   454  	EmbedTypeGifv    EmbedType = "gifv"
   455  	EmbedTypeArticle EmbedType = "article"
   456  	EmbedTypeLink    EmbedType = "link"
   457  )
   458  
   459  // MessageReactions holds a reactions object for a message.
   460  type MessageReactions struct {
   461  	Count int    `json:"count"`
   462  	Me    bool   `json:"me"`
   463  	Emoji *Emoji `json:"emoji"`
   464  }
   465  
   466  // MessageActivity is sent with Rich Presence-related chat embeds
   467  type MessageActivity struct {
   468  	Type    MessageActivityType `json:"type"`
   469  	PartyID string              `json:"party_id"`
   470  }
   471  
   472  // MessageActivityType is the type of message activity
   473  type MessageActivityType int
   474  
   475  // Constants for the different types of Message Activity
   476  const (
   477  	MessageActivityTypeJoin        MessageActivityType = 1
   478  	MessageActivityTypeSpectate    MessageActivityType = 2
   479  	MessageActivityTypeListen      MessageActivityType = 3
   480  	MessageActivityTypeJoinRequest MessageActivityType = 5
   481  )
   482  
   483  // MessageApplication is sent with Rich Presence-related chat embeds
   484  type MessageApplication struct {
   485  	ID          string `json:"id"`
   486  	CoverImage  string `json:"cover_image"`
   487  	Description string `json:"description"`
   488  	Icon        string `json:"icon"`
   489  	Name        string `json:"name"`
   490  }
   491  
   492  // MessageSnapshot represents a snapshot of a forwarded message.
   493  // https://discord.com/developers/docs/resources/message#message-snapshot-object
   494  type MessageSnapshot struct {
   495  	Message *Message `json:"message"`
   496  }
   497  
   498  // MessageReferenceType is a type of MessageReference
   499  type MessageReferenceType int
   500  
   501  // Known valid MessageReferenceType values
   502  // https://discord.com/developers/docs/resources/message#message-reference-types
   503  const (
   504  	MessageReferenceTypeDefault MessageReferenceType = 0
   505  	MessageReferenceTypeForward MessageReferenceType = 1
   506  )
   507  
   508  // MessageReference contains reference data sent with crossposted messages
   509  type MessageReference struct {
   510  	Type            MessageReferenceType `json:"type,omitempty"`
   511  	MessageID       string               `json:"message_id"`
   512  	ChannelID       string               `json:"channel_id,omitempty"`
   513  	GuildID         string               `json:"guild_id,omitempty"`
   514  	FailIfNotExists *bool                `json:"fail_if_not_exists,omitempty"`
   515  }
   516  
   517  func (m *Message) reference(refType MessageReferenceType, failIfNotExists bool) *MessageReference {
   518  	return &MessageReference{
   519  		Type:            refType,
   520  		GuildID:         m.GuildID,
   521  		ChannelID:       m.ChannelID,
   522  		MessageID:       m.ID,
   523  		FailIfNotExists: &failIfNotExists,
   524  	}
   525  }
   526  
   527  // Reference returns a MessageReference of the given message.
   528  func (m *Message) Reference() *MessageReference {
   529  	return m.reference(MessageReferenceTypeDefault, true)
   530  }
   531  
   532  // SoftReference returns a MessageReference of the given message.
   533  // If the message doesn't exist it will instead be sent as a non-reply message.
   534  func (m *Message) SoftReference() *MessageReference {
   535  	return m.reference(MessageReferenceTypeDefault, false)
   536  }
   537  
   538  // Forward returns a MessageReference for a forwarded message.
   539  func (m *Message) Forward() *MessageReference {
   540  	return m.reference(MessageReferenceTypeForward, true)
   541  }
   542  
   543  // ContentWithMentionsReplaced will replace all @<id> mentions with the
   544  // username of the mention.
   545  func (m *Message) ContentWithMentionsReplaced() (content string) {
   546  	content = m.Content
   547  
   548  	for _, user := range m.Mentions {
   549  		content = strings.NewReplacer(
   550  			"<@"+user.ID+">", "@"+user.Username,
   551  			"<@!"+user.ID+">", "@"+user.Username,
   552  		).Replace(content)
   553  	}
   554  	return
   555  }
   556  
   557  var patternChannels = regexp.MustCompile("<#[^>]*>")
   558  
   559  // ContentWithMoreMentionsReplaced will replace all @<id> mentions with the
   560  // username of the mention, but also role IDs and more.
   561  func (m *Message) ContentWithMoreMentionsReplaced(s *Session) (content string, err error) {
   562  	content = m.Content
   563  
   564  	if !s.StateEnabled {
   565  		content = m.ContentWithMentionsReplaced()
   566  		return
   567  	}
   568  
   569  	channel, err := s.State.Channel(m.ChannelID)
   570  	if err != nil {
   571  		content = m.ContentWithMentionsReplaced()
   572  		return
   573  	}
   574  
   575  	for _, user := range m.Mentions {
   576  		nick := user.Username
   577  
   578  		member, err := s.State.Member(channel.GuildID, user.ID)
   579  		if err == nil && member.Nick != "" {
   580  			nick = member.Nick
   581  		}
   582  
   583  		content = strings.NewReplacer(
   584  			"<@"+user.ID+">", "@"+user.Username,
   585  			"<@!"+user.ID+">", "@"+nick,
   586  		).Replace(content)
   587  	}
   588  	for _, roleID := range m.MentionRoles {
   589  		role, err := s.State.Role(channel.GuildID, roleID)
   590  		if err != nil || !role.Mentionable {
   591  			continue
   592  		}
   593  
   594  		content = strings.Replace(content, "<@&"+role.ID+">", "@"+role.Name, -1)
   595  	}
   596  
   597  	content = patternChannels.ReplaceAllStringFunc(content, func(mention string) string {
   598  		channel, err := s.State.Channel(mention[2 : len(mention)-1])
   599  		if err != nil || channel.Type == ChannelTypeGuildVoice {
   600  			return mention
   601  		}
   602  
   603  		return "#" + channel.Name
   604  	})
   605  	return
   606  }
   607  
   608  // MessageInteraction contains information about the application command interaction which generated the message.
   609  type MessageInteraction struct {
   610  	ID   string          `json:"id"`
   611  	Type InteractionType `json:"type"`
   612  	Name string          `json:"name"`
   613  	User *User           `json:"user"`
   614  
   615  	// Member is only present when the interaction is from a guild.
   616  	Member *Member `json:"member"`
   617  }
   618  
   619  // MessageInteractionMetadata contains metadata of an interaction, including relevant user info.
   620  type MessageInteractionMetadata struct {
   621  	// ID of the interaction.
   622  	ID string `json:"id"`
   623  	// Type of the interaction.
   624  	Type InteractionType `json:"type"`
   625  	// User who triggered the interaction.
   626  	User *User `json:"user"`
   627  	// IDs for installation context(s) related to an interaction.
   628  	AuthorizingIntegrationOwners map[ApplicationIntegrationType]string `json:"authorizing_integration_owners"`
   629  	// ID of the original response message.
   630  	// NOTE: present only on followup messages.
   631  	OriginalResponseMessageID string `json:"original_response_message_id,omitempty"`
   632  	// ID of the message that contained interactive component.
   633  	// NOTE: present only on message component interactions.
   634  	InteractedMessageID string `json:"interacted_message_id,omitempty"`
   635  	// Metadata for interaction that was used to open a modal.
   636  	// NOTE: present only on modal submit interactions.
   637  	TriggeringInteractionMetadata *MessageInteractionMetadata `json:"triggering_interaction_metadata,omitempty"`
   638  }