-
I tried to create a set of nested app commands But Not sure if I am misusing the lib or if it is a bug in 2.0.0alpha Here is the code I am using: import asyncio
import discord
from config import BOT_TOKEN
from utils.config import GUILD_ID
from discord.utils import get
from discord.ext import commands
from discord import Interaction
from discord.app_commands import command, Group
class ReadyEvent(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
await self.client.tree.sync(guild=self.client.get_guild(GUILD_ID))
print("The bot is ready!")
class TestCommand(commands.Cog):
def __init__(self, client):
self.client = client
test_group = Group(name='test', description='Test cmd group', guild_ids=[GUILD_ID])
test2_group = Group(name='test2', parent = test_group, description='Test2 cmd group', guild_ids=[GUILD_ID])
@command(name="test")
async def classic_welcome(self, interaction: Interaction) -> None:
"""Root group cmd, should be /test"""
await interaction.response.send_message("test")
@test_group.command(name="test_cmd")
async def classic_welcome(self, interaction: Interaction) -> None:
"""Cmd in test group, should be /test text_cmd"""
await interaction.response.send_message("test_cmd")
@test_group.command(name="test2")
async def classic_welcome(self, interaction: Interaction) -> None:
"""subgroup root, should be /test test2"""
await interaction.response.send_message("test2")
@test2_group.command(name="test2_cmd")
async def classic_welcome(self, interaction: Interaction) -> None:
"""sub group cmd, should be /test test2 test2_cmd"""
await interaction.response.send_message("test2_cmd")
async def main():
async with client:
await client.add_cog(ReadyEvent(client))
await client.add_cog(TestCommand(client))
await client.start(BOT_TOKEN)
intents = discord.Intents.all()
intents.members = True
client = commands.Bot(command_prefix = "!", intents=intents)
asyncio.run(main()) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
You have two |
Beta Was this translation helpful? Give feedback.
-
Thank you for your feedback. It is not always easy to make a minimal reproductible code without making some mistakes compare to the real code we have. I followed your advice, remove all redundancies and shadowing. Unfortunatly, the result is the same. I have now two groups: Only the first command is shown in Discord. Here is the new code, hopefully without any mistakes this time. import asyncio
import discord
from config import BOT_TOKEN
from utils.config import GUILD_ID
from discord.ext import commands
from discord import Interaction
from discord.app_commands import Group
class ReadyEvent(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
await self.client.tree.sync(guild=self.client.get_guild(GUILD_ID))
await self.client.tree.sync()
print("The bot is ready!")
class TestCommand(commands.Cog):
def __init__(self, client):
self.client = client
test_group = Group(name='test', description='Test cmd group', guild_ids=[GUILD_ID])
test2_group = Group(name='test2', parent = test_group, description='Test2 cmd group', guild_ids=[GUILD_ID])
@test_group.command(name="test_cmd")
async def test_cmd(self, interaction: Interaction) -> None:
"""Cmd in test group, should be /test text_cmd"""
await interaction.response.send_message("test_cmd")
@test2_group.command(name="test2_cmd")
async def test2_cmd(self, interaction: Interaction) -> None:
"""sub group cmd, should be /test test2 test2_cmd"""
await interaction.response.send_message("test2_cmd")
async def main():
async with client:
await client.add_cog(ReadyEvent(client))
await client.add_cog(TestCommand(client))
await client.start(BOT_TOKEN)
intents = discord.Intents.all()
intents.members = True
client = commands.Bot(command_prefix = "!", intents=intents)
asyncio.run(main()) |
Beta Was this translation helpful? Give feedback.
-
Very reactive, thank you ! |
Beta Was this translation helpful? Give feedback.
Thank you for your feedback. It is not always easy to make a minimal reproductible code without making some mistakes compare to the real code we have.
I followed your advice, remove all redundancies and shadowing. Unfortunatly, the result is the same.
I have now two groups:
/test
/test2
and one command in each :
/test test_cmd
/test test2 test2_cmd
Only the first command is shown in Discord.
/test test2 test2_cmd
is still not declared.Here is the new code, hopefully without any mistakes this time.