Cogs TypeError: object NoneType can't be used in 'await' expression in discord.py

Question:

I’ve been working on a discord bot for a personal server. I want to use cogs to separate the music player functionality from the main file.
I am raising this error when I load my main.py file:

discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.cog' raised an error: TypeError: object NoneType can't be used in 'await' expression      

My main.py file code related to cogs is this:

#   Cogs
async def load_extensions():
     for filename in os.listdir("./cogs"):
        if filename.endswith(".py"):
            # cut off the .py from the file name
            await bot.load_extension(f"cogs.{filename[:-3]}")
async def main():
    async with bot:
        await load_extensions()
        await bot.start(os.getenv('TOKEN'))

asyncio.run(main())     

In my cogs.py file:

import os, discord
from discord.ext import commands

class Test(commands.Cog):
    def __init__(self, client):
        self.client = client # sets the client variable so we can use it in cogs
        self.intents = discord.Intents.default()
        self.intents.message_content = True
    
    @commands.command()
    async def command(self, ctx):
        await ctx.send("Yes?")


def setup(client):
    client.add_cog(Test(client, ))

I initially had an error about intents, which was solved by adding self.intents, but I haven’t been able to solve this issue. I have utilized StackOverflow, but haven’t found anything specific to my issue.

Asked By: CompressedSquid

||

Answers:

The function def setup(client) must utilize async/await as it is a coroutine function.

The corrected code is:

    async def setup(client):
        await client.add(Test(bot)
Answered By: CompressedSquid