discord.py: Commands not working in cogs while using asyncio.run

Viewed 22

I have been trying to create a simple ping/pong command in discord but the command doesnt work. Here is the cog/test.py file:

from discord.ext import commands

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

    @commands.Cog.listener()
    async def on_ready(self):
        print("WORKED")

    @commands.command()
    async def ping(self, ctx):
        await ctx.send("Pong")


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

And here is the bot_launch.py file that is not in the cogs folder.

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

intents = discord.Intents.default()
bot = commands.Bot(command_prefix='$', intents=intents)

@bot.check
def check_guild(ctx):
    try:
        return ctx.guild.id == 947813835715256390
    except AttributeError:
        return True

async def load_extensions():
    for filename in os.listdir("./cogs"):
        if filename.endswith(".py"):
            await bot.load_extension(f"cogs.{filename[:-3]}")
            print(f"Loaded the following cog: {filename}")
        

with open("token_new.txt") as token_file:
    bot_token = token_file.read()

async def main():
    async with bot:
        await load_extensions()
        await bot.start(bot_token)

asyncio.run(main())

When I start the bot the console gives out this, indicating that the test.py file is indeed loaded:

Loaded the following cog: test.py
WORKED
0 Answers
Related