I’m having a problem that after restarting the bot, the slash commands doesn’t update, it stays the one I’ve made first, this is my simple code:
import discord
from discord.ext import commands
from discord_slash import cog_ext, SlashContext
class Slash(commands.Cog):
def __init__(self, bot):
self.bot = bot
@cog_ext.cog_slash(name="Soporte",description="Comando para ver las opciones de soporte")
async def _support(self, ctx: SlashContext):
await ctx.channel.send("✈️ Telegram: @Isaac_Sanzn💬 Discord: ElmerKao_#0058 n🌐 Página Web: https://nakiri.x10.mx/")
def setup(bot):
bot.add_cog(Slash(bot))
Here is a prove that everything is running as it should be:
But when I enter discord to run the command it only shows the test one I did before:
Could someone explain what is happening and any solution?
2
Answers
Found the issue, seems that you need to load the cogs before the something like this:
Here is how it should look like:
Here is the link of the question where I found the answer:
Link
They’re sort of in the middle of adding slash commands to discord.py but you can see a few examples in https://gist.github.com/Rapptz/c4324f17a80c94776832430007ad40e6 You seem to be using discord_slash, which I have not used.
I’m not quite sure how to do it in cogs, because I have mine in groups but basically what I’m doing is a combination of @bot.tree.command() in the main bot file and a few groups in separate files.
So here’s my main file
and then the simplegeneralgroup file
There should be three commands: /slash, which will prompt the user for a number and string, /generalgroup hello, and /generalgroup version
The main documentation for this stuff is https://discordpy.readthedocs.io/en/master/interactions/api.html?highlight=dropdown#decorators but the main "how to" is that you’ve gotta make a "tree", attach commands to that tree, and sync your tree for the commands to show up. discord.ext.Bot makes its own tree, which is why I’m using that instead of client, which I think doesn’t make a tree by default.
If you specify the guilds, the commands sync takes place instantly, but if you don’t specify the guild, I think it takes an hour to update or something like that, so specify the guild until you’re ready for deployment.