message.go 729 B

1234567891011121314151617181920212223242526
  1. // Discordgo - Discord bindings for Go
  2. // Available at https://github.com/bwmarrin/discordgo
  3. // Copyright 2015-2016 Bruce Marriner <bruce@sqls.net>. All rights reserved.
  4. // Use of this source code is governed by a BSD-style
  5. // license that can be found in the LICENSE file.
  6. // This file contains code related to the Message struct
  7. package discordgo
  8. import (
  9. "fmt"
  10. "strings"
  11. )
  12. // ContentWithMentionsReplaced will replace all @<id> mentions with the
  13. // username of the mention.
  14. func (m *Message) ContentWithMentionsReplaced() string {
  15. content := m.Content
  16. for _, user := range m.Mentions {
  17. content = strings.Replace(content, fmt.Sprintf("<@%s>", user.ID),
  18. fmt.Sprintf("@%s", user.Username), -1)
  19. }
  20. return content
  21. }