Cog-Creators / Red-DiscordBot

A multi-function Discord bot
https://docs.discord.red
GNU General Public License v3.0
4.81k stars 2.31k forks source link

Help command fails after being rate limited. #5905

Closed TheWizardofGauze closed 1 year ago

TheWizardofGauze commented 1 year ago

What Red version are you using?

3.4.18

Cog name

Core

Command name

help

What did you expect to happen?

All pages of the help list should be sent to DMs.

What actually happened?

A few pages are sent before the bot posts

Error in command 'help'. Check your console or logs for details.

and it abruptly stops.

How can we reproduce this error?

  1. Have a decent number of cogs installed (I have a total of 21).
  2. Run the 'help' command.
  3. Wait while it executes, until it stops and states the error.

Anything else?

Traceback:


Traceback (most recent call last):
  File "C:\Users\Ian\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\Users\Ian\AppData\Local\Programs\Python\Python38\lib\site-packages\redbot\core\commands\help.py", line 882, in red_help
    await ctx.bot.send_help_for(ctx, thing_to_get_help_for, from_help_command=True)
  File "C:\Users\Ian\AppData\Local\Programs\Python\Python38\lib\site-packages\redbot\core\bot.py", line 1214, in send_help_for
    return await self._help_formatter.send_help(
  File "C:\Users\Ian\AppData\Local\Programs\Python\Python38\lib\site-packages\redbot\core\commands\help.py", line 225, in send_help
    await self.format_bot_help(ctx, help_settings=help_settings)
  File "C:\Users\Ian\AppData\Local\Programs\Python\Python38\lib\site-packages\redbot\core\commands\help.py", line 639, in format_bot_help
    await self.make_and_send_embeds(ctx, emb, help_settings=help_settings)
  File "C:\Users\Ian\AppData\Local\Programs\Python\Python38\lib\site-packages\redbot\core\commands\help.py", line 531, in make_and_send_embeds
    await self.send_pages(ctx, pages, embed=True, help_settings=help_settings)
  File "C:\Users\Ian\AppData\Local\Programs\Python\Python38\lib\site-packages\redbot\core\commands\help.py", line 830, in send_pages
    msg = await destination.send(embed=page)
  File "C:\Users\Ian\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\abc.py", line 1065, in send
    data = await state.http.send_message(channel.id, content, tts=tts, embed=embed,
  File "C:\Users\Ian\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\http.py", line 267, in request
    raise HTTPException(r, data)
discord.errors.HTTPException: 429 Too Many Requests (error code: 31001): You are being rate limited.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Ian\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\Ian\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\Ian\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: HTTPException: 429 Too Many Requests (error code: 31001): You are being rate limited.
Flame442 commented 1 year ago

This is the second time this is getting reported, so something is definitely up with the rate limits today. I'm able to repro this right now running [p]help 3 times in a row. Seems like Discord pushed some kind of change to DM rate limits that dpy isn't handling correctly (are the headers wrong for some reason? wouldn't put it past Discord...). Keeping this open until this is resolved, or we hear word from Danny/Discord about what's up, because I swear this didn't happen in the past.

As a work around for now, you can use [p]helpset usemenus t to make help into a single-message menu, which should at least lower the amount of API requests it makes.

Edit: It also seems like the DM version of this issue only happens on 3.4.18, where as the reaction version of this issue only happens on 3.5.0.dev.

Flame442 commented 1 year ago

Minimal code to reproduce River's similar issue with reactions on dpy 2.0 only is the following:

await asyncio.gather(*[ctx.message.add_reaction(e) for e in guild.emojis[:10]])

(Assuming your guild has 10 emojis)

RheingoldRiver commented 1 year ago

I got another rate limit error printed to channel just now (even after rolling back). Here's the traceback:

Exception in command 'idsearch'
Traceback (most recent call last):
  File "/home/bot/tsubaki/prod/lib/python3.8/site-packages/discord/ext/commands/core.py", line 187, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/bot/.local/share/Red-DiscordBot/data/tsubaki_prod/cogs/CogManager/cogs/padinfo/padinfo.py", line 552, in idsearch
    await self._do_idsearch(ctx, query)
  File "/home/bot/.local/share/Red-DiscordBot/data/tsubaki_prod/cogs/CogManager/cogs/padinfo/padinfo.py", line 570, in _do_idsearch
    await self._do_monster_list(ctx, dbcog, query, queried_props, 'ID Search Results',
  File "/home/bot/.local/share/Red-DiscordBot/data/tsubaki_prod/cogs/CogManager/cogs/padinfo/padinfo.py", line 654, in _do_monster_list
    await parent_menu.transition(message, ims, MonsterListEmoji.refresh, ctx.author, **data)
  File "/home/bot/tsubaki/prod/lib/python3.8/site-packages/discordmenu/embed/menu.py", line 77, in transition
    await remove_reaction(message, emoji_clicked, member.id)
  File "/home/bot/tsubaki/prod/lib/python3.8/site-packages/discordmenu/discord_client.py", line 37, in remove_reaction
    await message.remove_reaction(emoji_cache.get_raw_emoji(emoji), member)
  File "/home/bot/tsubaki/prod/lib/python3.8/site-packages/discord/message.py", line 1027, in remove_reaction
    await self._state.http.remove_reaction(self.channel.id, self.id, emoji, member.id)
  File "/home/bot/tsubaki/prod/lib/python3.8/site-packages/discord/http.py", line 512, in request
    raise HTTPException(response, data)
discord.errors.HTTPException: 429 Too Many Requests (error code: 31001): You are being rate limited.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/bot/tsubaki/prod/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 1232, in invoke
    await ctx.command.invoke(ctx)
  File "/home/bot/tsubaki/prod/lib/python3.8/site-packages/discord/ext/commands/core.py", line 931, in invoke
    await injected(*ctx.args, **ctx.kwargs)  # type: ignore
  File "/home/bot/tsubaki/prod/lib/python3.8/site-packages/discord/ext/commands/core.py", line 196, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: HTTPException: 429 Too Many Requests (error code: 31001): You are being rate limited.
RheingoldRiver commented 1 year ago

I forgot to follow up about this. We revisited the upgrade about a month ago, and at this point Dpy was on 2.2, and the error is totally gone. So we think there was some issue temporarily with async handling of emotes in 1 release of Dpy and at least our error no longer applies. We're now fully caught up in the Red development branch and having no issues, the repro should not be possible anymore.

Not sure if the DM issue is still happening though.

Flame442 commented 1 year ago

Yup, seems like the reaction issue has been fixed either in a newer version of dpy or by discord. I can't replicate the DM issue on 3.4.18 anymore either, so it seems like that was a temporary thing as well. Thanks for bumping this.