Browse Source

Implement support for new member role endpoint (#289)

Implements support for the new member role add and delete endpoint
hammerandchisel/discord-api-docs#179
AI 8 years ago
parent
commit
2092185ec5
3 changed files with 24 additions and 0 deletions
  1. 1 0
      endpoints.go
  2. 22 0
      restapi.go
  3. 1 0
      structs.go

+ 1 - 0
endpoints.go

@@ -62,6 +62,7 @@ var (
 	EndpointGuildChannels        = func(gID string) string { return EndpointGuilds + gID + "/channels" }
 	EndpointGuildMembers         = func(gID string) string { return EndpointGuilds + gID + "/members" }
 	EndpointGuildMember          = func(gID, uID string) string { return EndpointGuilds + gID + "/members/" + uID }
+	EndpointGuildMemberRole      = func(gID, uID, rID string) string { return EndpointGuilds + gID + "/members/" + uID + "/roles/" + rID }
 	EndpointGuildBans            = func(gID string) string { return EndpointGuilds + gID + "/bans" }
 	EndpointGuildBan             = func(gID, uID string) string { return EndpointGuilds + gID + "/bans/" + uID }
 	EndpointGuildIntegrations    = func(gID string) string { return EndpointGuilds + gID + "/integrations" }

+ 22 - 0
restapi.go

@@ -732,6 +732,28 @@ func (s *Session) GuildMemberNickname(guildID, userID, nickname string) (err err
 	return
 }
 
+// GuildMemberRoleAdd adds the specified role to a given member
+//  guildID   : The ID of a Guild.
+//  userID    : The ID of a User.
+//  roleID 	  : The ID of a Role to be assigned to the user.
+func (s *Session) GuildMemberRoleAdd(guildID, userID, roleID string) (err error) {
+
+	_, err = s.RequestWithBucketID("PUT", EndpointGuildMemberRole(guildID, userID, roleID), nil, EndpointGuildMemberRole(guildID, userID, roleID))
+
+	return
+}
+
+// GuildMemberRoleRemove removes the specified role to a given member
+//  guildID   : The ID of a Guild.
+//  userID    : The ID of a User.
+//  roleID 	  : The ID of a Role to be removed from the user.
+func (s *Session) GuildMemberRoleRemove(guildID, userID, roleID string) (err error) {
+
+	_, err = s.RequestWithBucketID("DELETE", EndpointGuildMemberRole(guildID, userID, roleID), nil, EndpointGuildMemberRole(guildID, userID, roleID))
+
+	return
+}
+
 // GuildChannels returns an array of Channel structures for all channels of a
 // given guild.
 // guildID   : The ID of a Guild.

+ 1 - 0
structs.go

@@ -291,6 +291,7 @@ type Game struct {
 	URL  string `json:"url"`
 }
 
+// UnmarshalJSON unmarshals json to Game struct
 func (g *Game) UnmarshalJSON(bytes []byte) error {
 	temp := &struct {
 		Name string          `json:"name"`