From 6ecae2d78f8a4a56c5fa3578e4d0a3ced015104f Mon Sep 17 00:00:00 2001 From: Connor Edwards <38229097+cedws@users.noreply.github.com> Date: Mon, 29 Mar 2021 21:50:31 +0100 Subject: [PATCH] Bring back usage of API v8 This reverts commit 5700060e2e71fbc096f19c826e4d543ce727df2c. Discord have now moved API v6 to deprecated status. We should use v8 soon so that the tool doesn't stop working unexpectedly. --- client/api.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/client/api.go b/client/api.go index 87e8f63..6bbb486 100644 --- a/client/api.go +++ b/client/api.go @@ -10,7 +10,7 @@ import ( "time" ) -const api = "https://discord.com/api/v6" +const api = "https://discord.com/api/v8" const messageLimit = 25 var endpoints = map[string]string{ @@ -290,14 +290,15 @@ func (c *Client) request(method string, endpoint string, reqData interface{}, re if err != nil { return errors.Wrap(err, "Error decoding response") } - log.Infof("Server asked us to sleep for %v milliseconds", data.RetryAfter) - time.Sleep(time.Duration(data.RetryAfter) * time.Millisecond) + millis := time.Duration(data.RetryAfter*1000) * time.Millisecond + log.Infof("Server asked us to sleep for %v", millis) + time.Sleep(millis) // Try again once we've waited for the period that the server has asked us to. return c.request(method, endpoint, reqData, resData) case status == http.StatusForbidden: break case status == http.StatusUnauthorized: - return errors.New(fmt.Sprintf("Bad status code %v, is your token correct?", http.StatusText(res.StatusCode))) + return errors.New(fmt.Sprintf("Bad status code %v, log out and log back in to Discord or verify your token is correct", http.StatusText(res.StatusCode))) case status == http.StatusBadRequest: return errors.New(fmt.Sprintf("Bad status code %v", http.StatusText(res.StatusCode))) case status == http.StatusNoContent: @@ -357,5 +358,5 @@ type Messages struct { } type ServerWait struct { - RetryAfter int `json:"retry_after"` + RetryAfter float32 `json:"retry_after"` }