我是www.example.com的新用户Discord.py,当我尝试向我的discord bot添加斜杠命令时,我遇到了以下错误:
Traceback (most recent call last):
File "C:\programs\bot.py", line 5, in <module>
tree = app_commands.CommandTree(bot)
File "C:\Users\trnt\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\app_commands\tree.py", line 134, in __init__
raise ClientException('This client already has an associated command tree.')
discord.errors.ClientException: This client already has an associated command tree.
下面是我的代码:
import discord
from discord import app_commands
from discord.ext.commands import Bot
bot = Bot(command_prefix='!', intents=discord.Intents.all())
tree = app_commands.CommandTree(bot)
@bot.event
async def on_ready():
print(f'Bot Name: {bot.user}')
for server in bot.guilds:
await tree.sync(guild=discord.Object(id=server.id))
@tree.command(name="test", description="Test to see if slash commands are working")
async def test(interaction):
await interaction.response.send_message("Test")
bot.run('My Token')
我使用的是Discord.py 2.0.0和Python 3.10.11
有人能告诉我我哪里做错了吗?我在stackoverflow上搜索过问题,但没有一个对我有用。希望你能帮忙。谢谢你!
1条答案
按热度按时间qpgpyjmq1#
commands.Bot
已经有一个命令树,您不需要重新定义它。