本文整理汇总了Golang中github.com/bwmarrin/discordgo.Session.GuildRoles方法的典型用法代码示例。如果您正苦于以下问题:Golang Session.GuildRoles方法的具体用法?Golang Session.GuildRoles怎么用?Golang Session.GuildRoles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/bwmarrin/discordgo.Session
的用法示例。
在下文中一共展示了Session.GuildRoles方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: messageCreate
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.ChannelID != config.Discord.ChannelID {
return
}
ign := ""
member, err := s.State.Member(config.Discord.ServerID, m.Author.ID)
if err != nil {
log.Printf("[Discord] Failed to get member: %s (Make sure you have set the bot permissions to see members)", err.Error())
return
}
roles, err := s.GuildRoles(config.Discord.ServerID)
if err != nil {
log.Printf("[Discord] Failed to get roles: %s (Make sure you have set the bot permissions to see roles)", err.Error())
return
}
for _, role := range member.Roles {
if ign != "" {
break
}
for _, gRole := range roles {
if ign != "" {
break
}
if strings.TrimSpace(gRole.ID) == strings.TrimSpace(role) {
if strings.Contains(gRole.Name, "IGN:") {
splitStr := strings.Split(gRole.Name, "IGN:")
if len(splitStr) > 1 {
ign = strings.TrimSpace(splitStr[1])
}
}
}
}
}
if ign == "" {
return
}
msg := m.ContentWithMentionsReplaced()
//Maximum limit of 4k
if len(msg) > 4000 {
msg = msg[0:4000]
}
if len(msg) < 1 {
return
}
ign = sanitize(ign)
msg = sanitize(msg)
//Send message.
if err = Sendln(fmt.Sprintf("emote world 260 %s says from discord, '%s'", ign, msg)); err != nil {
log.Printf("[Discord] Error sending message to telnet (%s:%s): %s\n", ign, msg, err.Error())
return
}
log.Printf("[Discord] %s: %s\n", ign, msg)
}
示例2: updateRolesToDB
func updateRolesToDB(s *discordgo.Session, guild string) {
roles, _ := s.GuildRoles(guild)
pgDb := dbConn()
tx, err := pgDb.Begin()
checkErr(err)
for i := 0; i < len(roles); i++ {
_, err = tx.Exec("INSERT INTO roles(role, role_id) VALUES($1, $2)",
roles[i].Name, roles[i].ID)
checkErr(err)
}
tx.Commit()
pgDb.Close()
}