phenom4n4n / phen-cogs

My public cogs for Red, Discord bot.
https://phen-cogs.readthedocs.io/en/latest/
MIT License
120 stars 71 forks source link

Fix `AttributeError: module 'discord' has no attribute 'InvalidArgument'` #169

Closed japandotorg closed 1 year ago

japandotorg commented 1 year ago

Basically fixes this error:

Traceback (most recent call last):
  File "/{SPUNGED}/.local/share/Red-DiscordBot/data/MELON/cogs/CogManager/cogs/webhook/webhook.py", line 519, in send_to_channel
    return await webhook.send(allowed_mentions=allowed_mentions, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/{SPUNGED}/lib/python3.11/site-packages/discord/webhook/async_.py", line 1800, in send
    data = await adapter.execute_webhook(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/{SPUNGED}/lib/python3.11/site-packages/discord/webhook/async_.py", line 219, in request
    raise NotFound(response, data)
discord.errors.NotFound: 404 Not Found (error code: 10015): Unknown Webhook

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/{SPUNGED}/lib/python3.11/site-packages/discord/ext/commands/core.py", line 229, in wrapped
    ret = await coro(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/{SPUNGED}/.local/share/Red-DiscordBot/data/MELON/cogs/CogManager/cogs/webhook/webhook.py", line 159, in webhook_sudo
    await self.send_to_channel(
  File "/{SPUNGED}/.local/share/Red-DiscordBot/data/MELON/cogs/CogManager/cogs/webhook/webhook.py", line 520, in send_to_channel
    except (discord.InvalidArgument, discord.NotFound):
            ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'discord' has no attribute 'InvalidArgument'

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

Traceback (most recent call last):
  File "/{SPUNGED}/lib/python3.11/site-packages/discord/ext/commands/bot.py", line 1350, in invoke
    await ctx.command.invoke(ctx)
  File "/{SPUNGED}/melon-dpy2/redbot/core/commands/commands.py", line 783, in invoke
    await super().invoke(ctx)
  File "/{SPUNGED}/lib/python3.11/site-packages/discord/ext/commands/core.py", line 1642, in invoke
    await ctx.invoked_subcommand.invoke(ctx)
  File "/{SPUNGED}/lib/python3.11/site-packages/discord/ext/commands/core.py", line 1023, in invoke
    await injected(*ctx.args, **ctx.kwargs)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/{SPUNGED}/lib/python3.11/site-packages/discord/ext/commands/core.py", line 238, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: module 'discord' has no attribute 'InvalidArgument'

https://discordpy.readthedocs.io/en/stable/migrating.html?highlight=invalidargument#removal-of-invalidargument-exception

sravan1946 commented 1 year ago

The docs says here

Changed in version 2.0: This function will now raise ValueError instead of InvalidArgument.

So you should be using ValueError instead of TypeError

japandotorg commented 1 year ago

It says TypeError and/or ValueError image shouldn't we be using both if that's the case? Tho I think using just TypeError should be enough

japandotorg commented 1 year ago

The docs says here

Oh i see so Webhook.send now returns a ValueError instead of InvalidArgument