-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Labels
Description
Not the same as #153
An error occurs in production:
Client error:
GET https://discordapp.com/api/v6/guilds/***/members?limit=200&after=***
resulted in a429 Too Many Requests
response.
I thing that when we fetch the members of the guild we should be less agressive in the for loop.
secret-santa/src/Discord/UserExtractor.php
Lines 42 to 57 in 8e2f74b
do { | |
if ((time() - $startTime) > 19) { | |
throw new UserExtractionFailedException(DiscordApplication::APPLICATION_CODE, 'Took too much time to retrieve all the users on your team.'); | |
} | |
$lastMember = $lastMembers ? end($lastMembers) : null; | |
try { | |
/** @var GuildMember[] $members */ | |
$lastMembers = $this->apiHelper->getMembersInGuild($guildId, $lastMember ? $lastMember->user->id : null); | |
} catch (\Throwable $t) { | |
throw new UserExtractionFailedException(DiscordApplication::APPLICATION_CODE, 'Could not fetch members in guild.', $t); | |
} | |
$members = array_merge($members, $lastMembers); | |
} while (!empty($lastMembers)); |
Adding a "sleep" maybe?
There is also a lot of headers to help us mitigate this issue: https://discord.com/developers/docs/topics/rate-limits