#Pycord's example slash command in cog didn't work

1 messages · Page 1 of 1 (latest)

paper spire
#

Hello, i'm actually coding my bot but I wan't do slash command in cog. I used the slash in cog example in the github but it didn't work.

#

(ping me pls)

indigo lance
#

if i am not mistaked, you'll need to specify a name for the slash command as well, how else would you call it in discord

#
@commands.slash_command(
        name='ping',
        description='Pinging.')

or such

paper spire
#

oke thank I try

#

it doesn't work :/

indigo lance
#

any specific error that you get?

paper spire
#

nothing

indigo lance
#

try changing command.Bot(...) to discord.Bot()

paper spire
#

oke but how do I put the prefix ?

indigo lance
#

you don't need it if you use slash command

viral pumice
indigo lance
#

thus slash command

viral pumice
#

You load the cogs at the on_ready event, that is why it is not working

indigo lance
#

ah yeah yes

#

you need to load it seperatly or in a main

viral pumice
#

Just move it outside the event

paper spire
#

tysm it work

viral pumice
#

.close

vast pollenBOT
#

Done with your help thread?

Please close your own help thread by using </close:1009144375709814897> with @hasty bolt.

hasty boltBOT
#

This thread was archived by the user that opened it.

indigo lance
#

if you are funny you could use something like this:

import os

def load_cogs():
    for foldername, subfolders, filenames in os.walk('commands'):
        for filename in filenames:
            if filename.endswith('.py') and filename not in ['list of', 'files you', 'wanna ignore.py']:
                print_timestamp(filename, 'Trying to load in ')
                extension = os.path.join(foldername, filename).replace('.py', '').replace('/', '.')
                try:
                    bot.load_extension(extension)
                    print(f'Successfully loaded extension: {extension}')
                except Exception as e:
                    print(f'Failed to load extension {extension}: {e}')

load_cogs()
viral pumice
final vortex
#

okay chat didnt load bruh, discord istg

indigo lance
#

and also do i have more control over it and easy access for my own error logging script

indigo lance
#

thx, may use it if I would rewrite my bot

manic haven