#Cog with slash command group only works when I have one command in the group.

1 messages · Page 1 of 1 (latest)

pearl summit
#
class Stats(discord.Cog):
    def __init__(self, bot):
        self.bot = bot
        
    stats = SlashCommandGroup("stats", "Retreive stats about a user or a match.")

    @stats.command(name="username", description="Retrieve stats of a user by username.")
    async def username(self, context, username: str) -> None:
        await context.defer()
        await context.respond('test')
    
    @stats.command(name="usertest", description="Bruh")
    async def usertest(self, context, username: discord.Option(discord.SlashCommandOptionType.user)) -> None:
        await context.defer()
        await context.respond("Bruh")

    @stats.command(name="bruhtest", description="Bruh")
    async def bruhtest(self, context, username: discord.Option(discord.SlashCommandOptionType.user)):
        await context.defer()
        await context.respond("Bruh")
#

When I have the two stats.commands usertest and bruh test it, it does this

#

DEBUG:discord.bot: Bulk updating commands {'stats': 'delete'} for guild 1003529640557690981

#

then if i remove them it re adds the command

#

2022-08-22 07:39:51,671:DEBUG:discord.bot: Bulk updating commands {'stats': 'upsert'} for guild 1003529640557690981

topaz dew
#

how are you loading the ext/adding the cog

pearl summit
topaz dew
#

add store=False to load_extension

pearl summit
#

I did that, and ran it after and it still removes the commands from the server

topaz dew
#

didn't raise an error?

pearl summit
#

Failed to load extension info.
Cog, stats, has loaded.

topaz dew
#

I'd fix the error with info and see if that solves it

pearl summit
#

Failed to load extension stats. Extension 'cogs.stats' raised an error: TypeError: issubclass() arg 1 must be a class

#

I got rid of the info cog

#
import discord, asyncio
from discord.commands import SlashCommandGroup

class Stats(discord.Cog):
    def __init__(self, bot):
        self.bot = bot
        
    stats = SlashCommandGroup("stats", "Retreive stats about a user or a match.")

    @stats.command(name="username", description="Retrieve stats of a user by username.")
    async def username(self, context, username: str) -> None:
        await context.defer()
        await context.respond('test')
    
    @stats.command(name="usertest", description="Bruh")
    async def usertest(self, context, username: discord.Option(discord.SlashCommandOptionType.user)) -> None:
        await context.defer()
        await context.respond("Bruh")

    @stats.command(name="bruhtest", description="Bruh")
    async def bruhtest(self, context, username: discord.Option(discord.SlashCommandOptionType.user)) -> None:
        await context.defer()
        await context.respond("Bruh")

def setup(bot):
    bot.add_cog(Stats(bot))
topaz dew
#

I think that was fixed already

#

what version are you on

pearl summit
#

Of pycord?

topaz dew
#

yes

pearl summit
#

should be the latest let me check

#

2.0.1

wet cape
#

don't use discord.SlashCommandOptionType, just use the original type

#

like discord.User

pearl summit
#

deadass?

wet cape
#

SlashCommandOptionType is only used internally

#

i swear if this is in one of the examples i'm gonna cry

topaz dew
spring nova
#

eventually use commands.Cog and not discord

pearl summit
#

it is

wet cape
#

yeah but why

pearl summit
#

pl

#

okok

#

wait

#

so now its this

import discord, asyncio
from discord.commands import SlashCommandGroup

class Stats(discord.Cog):
    def __init__(self, bot):
        self.bot = bot
        
    stats = SlashCommandGroup("stats", "Retreive stats about a user or a match.")

    @stats.command(name="username", description="Retrieve stats of a user by username.")
    async def username(self, context, username: str) -> None:
        await context.defer()
        await context.respond('test')
    
    @stats.command(name="usertest", description="Bruh")
    async def usertest(self, context, username: discord.user) -> None:
        await context.defer()
        await context.respond("Bruh")

    @stats.command(name="bruhtest", description="Bruh")
    async def bruhtest(self, context, username: discord.user) -> None:
        await context.defer()
        await context.respond("Bruh")

def setup(bot):
    bot.add_cog(Stats(bot))
#

and im still getting

#

Failed to load extension stats. Extension 'cogs.stats' raised an error: TypeError: issubclass() arg 1 must be a class

wet cape
#

should be uppercase User but hmmmm

#

can you paste the full error

pearl summit
#

nvmn

#

wait

#

YOU DID IT

wet cape
#

sigh

pearl summit
#

it was User

wet cape
#

im updating examples

pearl summit
#

notuser

#

yes

#

pretty sure it was in one of the examples

#

uhh

wet cape
#

oh guide

topaz dew
#

i hate the typehinting syntax that we support

wet cape
#

i've always found name: discord.Option(type, ...) to work perfectly

#

while decorators have gone through hell and back

#

and i think name: type = discord.Option(...) also broke

#

maybe we should just be less lenient lol

topaz dew
wet cape
#

yeah but people always reported bugs with it

#

like i remember one beta version half the threads were because of decorators

topaz dew
#

I feel like I'm the only one who uses non-typehinting syntax

wet cape
#

do you just do discord.Option then? interesting

pearl summit
#

Yo yall must be speaking some ancient moon language

wet cape
#

one day

topaz dew
#

it's actually better because then I can typehint the parameter properly instead of my IDE saying it's supposed to be an Option class

pearl summit
#

I NEED to retake a python course

topaz dew
pearl summit
#

should i archive this

#

or nah