I am trying to build my first discord.py bot on a docker container. But when running it the traceback gave me the following error on the cogs_loader:
I used the following articles to try to fix the error, but I failed when trying refactor my code with their solution:
Bot base.load_extentstion was never awaited error message discord.py
"RuntimeWarning: coroutine 'BotBase.load_extension' was never awaited" after updating discord.py
This is my "client" file:
intents = discord.Intents.default()
bot = Bot(owner_id=env.owner_id, command_prefix='.', intents=intents)
async def load_extensions():
await bot.load_extension('bot.cogs.commands')
await bot.load_extension('bot.cogs.owner')
async def main():
await load_extensions()
await bot.start(env.TOKEN)
if __name__ == '__main__':
asyncio.get_event_loop().run_until_complete(main())
This is my __init__.py
file for the cogs (setup):
intents = discord.Intents.default()
bot = Bot(owner_id=env.owner_id, command_prefix='.', intents=intents)
async def setup(bot):
"""
Init bot's cogs
"""
await bot.add_cog(Commands(bot))
await bot.add_cog(Owner(bot))
This is the traceback when running __main__.py
:
Traceback (most recent call last):
File "D:/GitHub/Mamey_bot/bot/__main__.py", line 83, in <module>
asyncio.get_event_loop().run_until_complete(main())
File "C:\Program Files\Python38\lib\asyncio\base_events.py", line 616, in run_until_complete
return future.result()
File "D:/GitHub/Mamey_bot/bot/__main__.py", line 62, in main
await load_extensions()
File "D:/GitHub/Mamey_bot/bot/__main__.py", line 57, in load_extensions
await bot.load_extension('bot.cogs.commands')
TypeError: object NoneType can't be used in 'await' expression
If I rewrite main()
in __main__.py
like in the first article:
async def main():
async with bot:
await load_extensions()
await bot.start(env.TOKEN)
I would get a different traceback:
Traceback (most recent call last):
File "D:/GitHub/Mamey_bot/bot/__main__.py", line 84, in <module>
asyncio.get_event_loop().run_until_complete(main())
File "C:\Program Files\Python38\lib\asyncio\base_events.py", line 616, in run_until_complete
return future.result()
File "D:/GitHub/Mamey_bot/bot/__main__.py", line 62, in main
async with bot:
AttributeError: __aexit__
How can I fix this?
If I don't use asynchronous functions when running the bot in the container, the bot will get online, but the commands wont work.