Browse Source

Add GuildMemberNickname

jonas747 8 years ago
parent
commit
c8b796b223
2 changed files with 29 additions and 0 deletions
  1. 13 0
      restapi.go
  2. 16 0
      restapi_test.go

+ 13 - 0
restapi.go

@@ -665,6 +665,19 @@ func (s *Session) GuildMemberMove(guildID, userID, channelID string) (err error)
 	return
 }
 
+// GuildMemberNickname updates the nickname of a guild member
+// guildID   : The ID of a guild
+// userID    : The ID of a user
+func (s *Session) GuildMemberNickname(guildID, userID, nickname string) (err error) {
+
+	data := struct {
+		Nick string `json:"nick"`
+	}{nickname}
+
+	_, err = s.Request("PATCH", GUILD_MEMBER(guildID, userID), data)
+	return
+}
+
 // GuildChannels returns an array of Channel structures for all channels of a
 // given guild.
 // guildID   : The ID of a Guild.

+ 16 - 0
restapi_test.go

@@ -186,6 +186,22 @@ func TestGuildRoles(t *testing.T) {
 
 }
 
+func TestGuildMemberNickname(t *testing.T) {
+
+	if envGuild == "" {
+		t.Skip("Skipping, DG_GUILD not set.")
+	}
+
+	if dg == nil {
+		t.Skip("Skipping, dg not set.")
+	}
+
+	err := dg.GuildMemberNickname(envGuild, "@me/nick", "testnickname")
+	if err != nil {
+		t.Errorf("GuildNickname returned error: %+v", err)
+	}
+}
+
 // TestChannelMessageSend2 tests the ChannelMessageSend() function. This should not return an error.
 func TestChannelMessageSend2(t *testing.T) {