how giveaway boat avoids rate limits
on giveaway boat, in the raffles pagination:
- there's an option to show the username instead of the mention.
i know the bot can’t fetch users on demand (because of api rate limits). how do they manage to do that without hitting the limit? the only thing i can think of is caching users when the bot logs in.
also, is there any other solution?
16 Replies
Fetch will always check the cache first before fetching a user from the Discord API unless told not to.
so, does it really make 10 different fetches every time you click to change the page?
Only if it's 10 uncached users
but in this case, since it’s a big bot and there are lots of users, isn’t that somehow harmful? for example, it would be hundreds of users browsing hundreds of giveaways and doing multiple paginations at the same time.
i’ve always thought (even with a small bot) that doing lots of fetches would cause rate limits.
Assuming you're operating at that scale. Why not just store the usernames where you store their user IDs?
in that case, are you saying to store it in cache or something like a database?
if it’s the second option, wouldn’t username changes be a problem?
Yeah probably. But also you're just relying on it for display information. You aren't using it for any operation. That's what the id is for.
Truthfully, I don't think you should worry about rate limit until you actually are rate limited. The built-in cache to Discord JS should work well enough
i understand, thank you so much for helping.
last question, i know it’s hard to tell, but do you have any idea how many fetches it would take to hit the rate limit?
considering they’re different users
Rate limits are all dynamic. There's no number to give.
Every request will tell you how many requests you have left until a certain time but that can change throughout the day or based on server load or your bots load on the API
that makes sense.
i was planning to build a giveaway system with an audit feature, basically, when the draw happens, it would send a txt file containing every participant’s discord name, their ticket count, and the seed used to verify the winning number.
however, i feel like this might not be a good idea because of the api limitations. i know there’s the
guild.members fetch, but some users inevitably leave the server before the draw happens. would you suggest continuing with this approach or trying a different one?You're allowed to fetch the entire members list of a server once per guild every 30 seconds. And using the
GuildMembers intent, DiscordJS will keep that cache updated from gateway events
That, or just cache the user when they click the button to enter the raffle
If you're worried about users leaving before the draw, listen to the guildMemberRemove event and remove them from the raffle if they leavetysm
oops yup wrong one
@thiago i said the wrong intent...
np
The thread owner has marked this issue as solved.