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

Discussão em 'Python' iniciado por Stack, Janeiro 3, 2025.

  1. Stack

    Stack Membro Participativo

    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.

    Continue reading...

Compartilhe esta Página