Pycord-Development/pycord

Subcommand groups not showing up in the Slash Command channel

Erwin-Ny opened this issue · 4 comments

Summary

Subcommand group not showing up

Reproduction Steps

I tidied up my ticket command by turning it into a subcommand group, hoping it would make things easier to manage and fix bugs. But no luck. I followed the Pycord guide step by step, but it still didn't work.

To be sure, I checked if it was syncing properly, and it was. So, it seems like something else is going wrong.

Minimal Reproducible Code

import discord
from discord.ext import commands

bot = commands.Bot()
ticket_command = discord.SlashCommandGroup("ticket", "Create and delete tickets")

class Ticket(commands.Cog):
    def __init__(self, bot: commands.Bot):
        self.bot = bot

    @ticket_command.command(description="Create a ticket channel")
    async def create_ticket(self, ctx: discord.ApplicationContext):
        guild = ctx.guild
        try:
            overwrites = {
                guild.default_role: discord.PermissionOverwrite(read_messages=False),
                ctx.author: discord.PermissionOverwrite(read_messages=True)
            }
            channel = await guild.create_text_channel(name="ticket", overwrites=overwrites)

            embed = discord.Embed(title="Your ticket has been created", color=0x0a192f)
            ticket_channel_link = f"[Go to Ticket Channel](https://discord.com/channels/{guild.id}/{channel.id})"
            embed.add_field(name="Ticket Channel", value=ticket_channel_link, inline=False)
            await ctx.respond(embed=embed)

            # Save the ticket channel ID for later reference
            self.ticket_id = channel.id

        except Exception as e:
            error_embed = discord.Embed(title="Something went wrong", description=str(e), color=0x00b48a)
            await ctx.respond(embed=error_embed)

    @ticket_command.command(description="Close your ticket channel")
    async def close_ticket(self, ctx: discord.ApplicationContext):
        # Retrieve the ticket channel ID
        ticket_id = getattr(self, "ticket_id", None)
        if ticket_id:
            channel = bot.get_channel(ticket_id)
            try:
                await channel.delete()
            except discord.HTTPException as e:
                error_embed = discord.Embed(title="Error", description=str(e), color=0xFF0000)
                await ctx.respond(embed=error_embed)
        else:
            await ctx.respond("No ticket channel found.")

def setup(bot: commands.Bot):
    bot.add_cog(Ticket(bot))

Expected Results

Show up in the slash command list

Actual Results

Nothing happened

Intents

bot = discord.Bot(intents=discord.Intents.all())

System Information

  • Python v3.9.13-final
  • py-cord v2.5.None-final
  • aiohttp v3.9.5

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

No response

Your ticket command was never added to your bot, it needs to be either inside a cog or added manually (bot.add_application_command I think)

Your ticket command was never added to your bot, it needs to be either inside a cog or added manually (bot.add_application_command I think)

def setup(bot: commands.Bot):
bot.add_cog(Ticket(bot))

It's in the last part of my code.

You add the cog but never the command group.

Since the command group is outside the cog, it needs to be added manually afaik