本文整理汇总了Golang中github.com/bwmarrin/discordgo.Session.GuildRoleCreate方法的典型用法代码示例。如果您正苦于以下问题:Golang Session.GuildRoleCreate方法的具体用法?Golang Session.GuildRoleCreate怎么用?Golang Session.GuildRoleCreate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/bwmarrin/discordgo.Session
的用法示例。
在下文中一共展示了Session.GuildRoleCreate方法的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)
}