discord.py, using slash command and prefix at the same time

Question:

How to run a slash command with a prefix at the same time in Discord? Bigger bots like mee6 have that you can use the prefix ! and / at the same time, there is I think only one way to use slahscommands on discord.py and that is by using discord-py-slash-commands, I tried many ways, but all didn’t work, I tried using two @ like @cog_ext.cog_slash and @commands.command at the same time but for me that was logical to do, but that is only because I’m a beginner in python. When I run them in two separate cogs it says on the slash command This interaction failed or some kind of other error, so my question is if it is possible to have slash commands and a prefix running on one command, for example help(so I can do !help and /help), and if it is then how can I do it?

Asked By: adi1708

||

Answers:

You need to write the command twice, one with @commands.command and a second with @cog_ext.cog_slash

Maybe if the commands function is very long or you just do not want it twice you can spil it it into another funtion that you call with both commands

async def cmd(author):
    # do your commands stuff here

@commands.command(name="cmd")
async def command_cmd(ctx):
    await cmd(ctx.author) # call the cmd function

@cog_ext.cog_slash(name="cmd") # I'm not 100% sure if it works like that since i 
async def slash_cmd(ctx):      # 
    await cmd(ctx.author) # call the cmd function


Answered By: Guddi

Use the decorator @commands.hybrid_command

Example: @commands.hybrid_command(name="commandname", description="Command description.")

Answered By: caffeinatedbaby
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.