Skip to content

Commit

Permalink
Treat retry_after on API response as seconds rather than milliseconds.
Browse files Browse the repository at this point in the history
See https://discord.com/developers/docs/topics/rate-limits#exceeding-a-rate-limit:
  retry_after - float - The number of seconds to wait before submitting another request.
  • Loading branch information
Alen committed May 2, 2022
1 parent 6824343 commit 17c1d9d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions deleteDiscordMessages.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@

// not indexed yet
if (resp.status === 202) {
const w = (await resp.json()).retry_after;
const w = (await resp.json()).retry_after * 1000;
throttledCount++;
throttledTotalTime += w;
log.warn(`This channel wasn't indexed, waiting ${w}ms for discord to index it...`);
Expand All @@ -783,7 +783,7 @@
if (!resp.ok) {
// searching messages too fast
if (resp.status === 429) {
const w = (await resp.json()).retry_after;
const w = (await resp.json()).retry_after * 1000;
throttledCount++;
throttledTotalTime += w;
searchDelay += w; // increase delay
Expand Down Expand Up @@ -867,7 +867,7 @@
if (!resp.ok) {
// deleting messages too fast
if (resp.status === 429) {
const w = (await resp.json()).retry_after;
const w = (await resp.json()).retry_after * 1000;
throttledCount++;
throttledTotalTime += w;
deleteDelay = w; // increase delay
Expand Down
6 changes: 3 additions & 3 deletions src/deleteMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async function deleteMessages(authToken, authorId, guildId, channelId, minId, ma

// not indexed yet
if (resp.status === 202) {
const w = (await resp.json()).retry_after;
const w = (await resp.json()).retry_after * 1000;
throttledCount++;
throttledTotalTime += w;
log.warn(`This channel wasn't indexed, waiting ${w}ms for discord to index it...`);
Expand All @@ -95,7 +95,7 @@ async function deleteMessages(authToken, authorId, guildId, channelId, minId, ma
if (!resp.ok) {
// searching messages too fast
if (resp.status === 429) {
const w = (await resp.json()).retry_after;
const w = (await resp.json()).retry_after * 1000;
throttledCount++;
throttledTotalTime += w;
searchDelay += w; // increase delay
Expand Down Expand Up @@ -179,7 +179,7 @@ async function deleteMessages(authToken, authorId, guildId, channelId, minId, ma
if (!resp.ok) {
// deleting messages too fast
if (resp.status === 429) {
const w = (await resp.json()).retry_after;
const w = (await resp.json()).retry_after * 1000;
throttledCount++;
throttledTotalTime += w;
deleteDelay = w; // increase delay
Expand Down

0 comments on commit 17c1d9d

Please sign in to comment.