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


Golang Session.GuildRoleEdit方法代碼示例

本文整理匯總了Golang中github.com/bwmarrin/discordgo.Session.GuildRoleEdit方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.GuildRoleEdit方法的具體用法?Golang Session.GuildRoleEdit怎麽用?Golang Session.GuildRoleEdit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/bwmarrin/discordgo.Session的用法示例。


在下文中一共展示了Session.GuildRoleEdit方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: addRole

func addRole(s *discordgo.Session, GuildID string, UserID string, arg string) string {
	g, err := s.State.Guild(GuildID)
	if err != nil {
		fmt.Println(err)
		return "You fucking broke it~"
	}

	exists, role := roleExists(g, arg)

	if !exists {
		if !strings.HasPrefix(arg, "yes") {
			return fmt.Sprintf("I can't find such group~ Are you sure you didn't mistype it? Say **!subscribe yes %s** to create a new one~", arg)
		}

		if len(arg) < 5 {
			return "Are you sure you actually typed a name?~"
		}

		arg = arg[4:]

		exists, role = roleExists(g, arg)

		if !exists {
			newRole, err := s.GuildRoleCreate(GuildID)

			if err != nil {
				fmt.Println(err)
				return "Failed to create role"
			}

			role, err = s.GuildRoleEdit(GuildID, newRole.ID, arg, newRole.Color, newRole.Hoist, 37080064, true)
			if err != nil {
				fmt.Println(err)

				err = s.GuildRoleDelete(GuildID, newRole.ID)

				if err != nil {
					fmt.Println(err)
				}

				return "You fucking broke it~"
			}
			fmt.Println(role)
		} else {
			return "Why are you trying to recreate that group?"
		}
	}

	member, err := s.GuildMember(GuildID, UserID)
	if err != nil {
		fmt.Println(err)
		return ""
	}

	if exists {
		for _, _role := range member.Roles {
			if _role == role.ID {
				return fmt.Sprintf("You're already subscribed to %s ~", arg)
			}
		}
	}

	newRoles := append(member.Roles, role.ID)

	err = s.GuildMemberEdit(GuildID, UserID, newRoles)
	if err != nil {
		fmt.Println(err)
		return "I can't touch that group dude, do it yourself~"
	}

	if exists {
		return fmt.Sprintf("You're now subscribed to %s~", arg)
	}

	return fmt.Sprintf("Created and subscribed to %s", arg)
}
開發者ID:softashell,項目名稱:lewdbot-discord,代碼行數:76,代碼來源:roles.go


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