0

After i rewritten my extension loading code in discord.py 2.0 everything works fine except if i got any errors in a command it will not send me a error. i have to figure it out with prints this is very annoying tho. Is there a way to get the errors shown again, I got no error event or listeners

client = commands.Bot(command_prefix="!", intents=discord.Intents().all())
client.remove_command('help')

async def load_extensions():
    for filename in os.listdir("./cogs"):
        if filename.endswith(".py"):
            await client.load_extension(f"cogs.{filename[:-3]}")

async def main():
    async with client:
        await load_extensions()
        await client.start(tokn)
asyncio.run(main())

So after i deleted all cogs and nothing was loaded i still got no errors on anything, I also replaced the main function with client.run(token) itl run the bot but the cogs wont load but i get errors on command tho. anyone knows a fix?

lEPr
  • 9
  • 3
  • [Welcome to StackOverflow.](https://stackoverflow.com/tour) See [`on_command_error`](https://discordpy.readthedocs.io/en/stable/ext/commands/api.html#discord.ext.commands.Bot.on_command_error) and [`on_error`](https://discordpy.readthedocs.io/en/stable/ext/commands/api.html#discord.ext.commands.Bot.on_error). Also, please see [ask] and [help/on-topic] and [how to format posts](https://stackoverflow.com/editing-help). – The Amateur Coder Jun 23 '22 at 15:26
  • Try `asyncio.get_event_loop().run_until_complete(main())` – Eric Jin Jun 24 '22 at 01:55

1 Answers1

1

The default behaviour was changed to use the logging framework instead.

Docs example & explanation: https://discordpy.readthedocs.io/en/latest/logging.html

Seeing as you're not using Client.run(), but rather Client.start(), there's no default handler being provided, so you have to do it yourself.

After following the example in the docs page linked above, your errors should get logged in a file named discord.log (or however you decided to name it).

If you'd like it to output to stdout (or stderr) like before, either do that manually in on_command_error(), or configure stderr as your handler for the logger instead of the RotatingFileHandler. This answer explains how to do that: https://stackoverflow.com/a/14058475/13568999

stijndcl
  • 5,294
  • 1
  • 9
  • 23