'RuntimeWarning: coroutinge "main" was never awatied' error when creating cogs

Question:

I am trying to learn discord.py v2.0 but I just cant figure out how I am supposed to use cogs and slash commands at the same time. I am trying to look at a realesed example of slash commands (https://github.com/Rapptz/discord.py/tree/master/examples/app_commands) and just try to mix it up so it works with cogs but I cant get it to work.

Here is my current main.py:

import os
import asyncio
#---
import discord
from discord import app_commands
from discord.ext import commands
#---

MY_GUILD = discord.Object(id=1041079018713260173)  # replace with your guild id
TOKEN = "token"

intents = discord.Intents.default()
bot = commands.Bot(command_prefix="!", intents=intents)

class abot(discord.Client):
    def __init__(self, *, intents: discord.Intents):
        super().__init__(intents=intents)
        self.bot = bot
        self.synced = False
        self.tree = app_commands.CommandTree(self.bot)

    async def on_ready(self):
        await self.tree.sync(guild=MY_GUILD)
        self.synced = True
        print("Online")

async def load():
    for filename in os.listdir("./cogs"):
        if filename.endswith(".py"):
            await bot.load_extension(f"cogs.{filename[:-3]}")
            print(f'[i]: Loaded "{filename}" into cogs')

async def main():
    await load()
    await bot.start(TOKEN)

asyncio.run(main())

Here is my event.py inside a folder called "cogs":

import asyncio
import os
#---
import discord
from discord.ext import commands

status = "test"

class events(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.Cog.listener()
    async def on_message(self, message):
        print("test")
    
async def setup(bot):
    await bot.add_cog(events(bot))
Asked By: Snabba_Snigeln

||

Answers:

When using your code, I didn’t have the same error. But changing

async def setup(bot):
    await bot.add_cog(bot)

with

async def setup(bot):
    await bot.add_cog(events(bot))

worked for me.

Answered By: Clement Genninasca