當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Session.GuildRoles方法代碼示例

本文整理匯總了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)
}
開發者ID:Xackery,項目名稱:discordeq,代碼行數:59,代碼來源:discord.go

示例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()
}
開發者ID:Muckfoot,項目名稱:Go,代碼行數:14,代碼來源:basic_bot.go


注:本文中的github.com/bwmarrin/discordgo.Session.GuildRoles方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。