Browse Source

Added reason go GuildBanCreate (#367)

* Added reason go GuildBanCreate

* Added GuildBanCreateWithReason
jonas747 7 years ago
parent
commit
4fb7760b59
1 changed files with 18 additions and 1 deletions
  1. 18 1
      restapi.go

+ 18 - 1
restapi.go

@@ -663,11 +663,28 @@ func (s *Session) GuildBans(guildID string) (st []*GuildBan, err error) {
 // userID    : The ID of a User
 // days      : The number of days of previous comments to delete.
 func (s *Session) GuildBanCreate(guildID, userID string, days int) (err error) {
+	return s.GuildBanCreateWithReason(guildID, userID, "", days)
+}
+
+// GuildBanCreateWithReason bans the given user from the given guild also providing a reaso.
+// guildID   : The ID of a Guild.
+// userID    : The ID of a User
+// reason    : The reason for this ban
+// days      : The number of days of previous comments to delete.
+func (s *Session) GuildBanCreateWithReason(guildID, userID, reason string, days int) (err error) {
 
 	uri := EndpointGuildBan(guildID, userID)
 
+	queryParams := url.Values{}
 	if days > 0 {
-		uri = fmt.Sprintf("%s?delete-message-days=%d", uri, days)
+		queryParams.Set("delete-message-days", strconv.Itoa(days))
+	}
+	if reason != "" {
+		queryParams.Set("reason", reason)
+	}
+
+	if len(queryParams) > 0 {
+		uri += "?" + queryParams.Encode()
 	}
 
 	_, err = s.RequestWithBucketID("PUT", uri, nil, EndpointGuildBan(guildID, ""))