'Discordpy Slash command don't update afer restarting bot

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_Sanz\n💬 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: Terminal

But when I enter discord to run the command it only shows the test one I did before: enter image description here

Could someone explain what is happening and any solution?



Solution 1:[1]

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

import discord
import simplegeneralgroup
from config import TOKEN
MY_GUILD = discord.Object(id=1234567890)

class MyBot(discord.ext.commands.Bot):
    async def on_ready(self):
        await self.tree.sync(guild=MY_GUILD)

bot: discord.ext.commands.Bot = MyBot

@bot.tree.command(guild=MY_GUILD)
async def slash(interaction: discord.Interaction, number: int, string: str):
    await interaction.response.send_message(f'Modify {number=} {string=}', ephemeral=True)

bot.tree.add_command(simplegeneralgroup.Generalgroup(bot), guild=MY_GUILD)

if __name__ == "__main__":
    bot.run(TOKEN)

and then the simplegeneralgroup file

import discord
from discord import app_commands as apc
class Generalgroup(apc.Group):
    """Manage general commands"""
    def __init__(self, bot: discord.ext.commands.Bot):
        super().__init__()
        self.bot = bot

    @apc.command()
    async def hello(self, interaction: discord.Interaction):
        await interaction.response.send_message('Hello')

    @apc.command()
    async def version(self, interaction: discord.Interaction):
        """tells you what version of the bot software is running."""
        await interaction.response.send_message('This is an untested test version')

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jeffrey DeLucca