Example #1
0
func (d *Discord) replaceChannelNames(message *discordgo.Message) {
	message.Content = channelIDRegex.ReplaceAllStringFunc(message.Content, func(str string) string {
		c, err := d.Channel(str[2 : len(str)-1])
		if err != nil {
			return str
		}

		return "#" + c.Name
	})
}
Example #2
0
func (d *Discord) replaceRoleNames(message *discordgo.Message) {
	message.Content = roleIDRegex.ReplaceAllStringFunc(message.Content, func(str string) string {
		roleID := str[3 : len(str)-1]

		c, err := d.Channel(message.ChannelID)
		if err != nil {
			return str
		}

		g, err := d.Guild(c.GuildID)
		if err != nil {
			return str
		}

		for _, r := range g.Roles {
			if r.ID == roleID {
				return "@" + r.Name
			}
		}

		return str
	})
}