-
I create a CommandTree with an error, It says "This client already has an associated command tree." here is my code import asyncio
import discord_together
from discord import AutoShardedClient, Intents
from discord.ext import commands
from discord.app_commands import CommandTree
from config import *
# bot = AutoShardedClient()
bot = commands.AutoShardedBot(command_prefix="t!", intents=Intents.all())
# bot._connection._command_tree = None
Applications = CommandTree(bot)
@bot.event
async def on_ready():
bot.togetherControl = await discord_together.DiscordTogether(token)
print('new version!!!')
async def module_init():
await bot.load_extension('Commands')
asyncio.run(module_init())
bot.run(token) I want to know why this situation ocurred, I look at the source code, but I still don't know. If I execute line 9, it doesn't have any error. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
As the error tells you, the You can access it under bot = commands.AutoShardedBot(command_prefix="t!", intents=Intents.all())
@bot.tree.command()
async def example(interaction):
... |
Beta Was this translation helpful? Give feedback.
-
No need to do Applications = CommandTree(bot), theres already an existing attribute |
Beta Was this translation helpful? Give feedback.
-
thank you all. |
Beta Was this translation helpful? Give feedback.
As the error tells you, the
Bot
andAutoShardedBot
classes already have a comand tree registered by default which is used to register application commands found in Cogs.You can access it under
Bot.tree
to add your commands, just as you would with a tree that you create yourself.