当前位置: 首页>>代码示例>>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;未经允许,请勿转载。