The error itself tells you what is wrong...
main.py:15: RuntimeWarning: coroutine 'BotBase.load_extension' was never awaited bot.load_extension(f"cogs.{filename[:-3]}") RuntimeWarning: Enable tracemalloc to get the object allocation traceback
The important part is "coroutine 'BotBase.load_extension' was never awaited"
discord.py uses coroutines all around so you have to learn to use await
whenever it is needed.
Long story short, you must use await
next to load_extension()
...
Fixed code:
import os
from discord.ext import commands
bot = commands.Bot(command_prefix="!c", intents=discord.Intents.all(), case_insensitive=True)
@bot.event
async def on_ready():
print(f"{bot.user} is online!")
for filename in os.listdir("./cogs"):
if filename.endswith(".py"):
await bot.load_extension(f"cogs.{filename[:-3]}")
bot.run("im not showing you my bot token lol")
That should work as long as there are no other problems in your code but it looks fine lol
Edit: That actually didn't work because you cannot use await
outside a function, I came to this problem myself when updating my bot to v2.0, here's my workaround (I got help from people from dpy discord, good place to be aided):
async def main():
async with bot:
# This is kinda the same as you had it before
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
await bot.load_extension(f'cogs.{filename[:-3]}')
await bot.start("token"))
asyncio.run(main())
This code should actually work or at least it did work for me lol, if you are following a youtube tutorial (which you shouldn't), it might be outdated so also remember to update your cog's code to keep the async stuff, you might need to update
def setup(client): # "client" or "bot", same thing
client.add_cog(MyCog(client))
to
async def setup(client):
await client.add_cog(MyCog(client))
For future reference I would advise you to check the docs in https://discordpy.readthedocs.io/en/stable/ and look for dpy's discord server to ask questions like this :)