我使用https://replit.com/为朋友构建一个不和谐的机器人,在我运行命令之前一切都很顺利,它给了我这个错误,我知道这意味着什么或者如何修复它,有人能帮忙吗?
错误:
Ignoring exception in command <nextcord.application_command.SlashApplicationCommand object at 0x7f4bc8784df0>:
Traceback (most recent call last):
File "/home/runner/nextcord/venv/lib/python3.8/site-packages/nextcord/application_command.py", line 824, in invoke_callback_with_hooks
await self(interaction, *args, **kwargs)
File "main.py", line 37, in delete_things
confirm = await Confirm('Delete everything?').prompt(ctx)
File "main.py", line 26, in prompt
await self.start(ctx, wait=True)
File "/home/runner/nextcord/venv/lib/python3.8/site-packages/nextcord/ext/menus/menus.py", line 684, in start
self.bot = ctx.bot
AttributeError: 'Interaction' object has no attribute 'bot'
The above exception was the direct cause of the following exception:
nextcord.errors.ApplicationInvokeError: Command raised an exception: AttributeError: 'Interaction' object has no attribute 'bot'您可以在这里看到代码,https://replit.com/join/qcbhddmqnn-hamishmcd
发布于 2022-08-09 17:38:49
您需要将交互传递给交互kwarg。
斜杠命令为您提供一个名为Interaction的类型,而不是Context,因此不应该将其称为ctx。
参见本例:https://menus.docs.nextcord.dev/en/stable/ext/menus/menu_examples/#slash-commands
@bot.slash_command()
async def slash_menu(interaction: nextcord.Interaction):
await MySlashButtonMenu().start(interaction=interaction)注意,在开始时,斜杠命令交互作为关键字参数传递给函数。
在您的示例中,您需要提示符来进行交互,并使用self.interaction来发送消息,而不是使用ctx或通道。
async def send_initial_message(self, ctx, channel):
await self.interaction.response.send_message(self.msg, view=self)
return await self.interaction.original_message()
...
async def prompt(self, interaction):
await self.start(interaction=interaction, wait=True)
return self.result
...
@bot.slash_command()
async def delete_things(interaction):
confirm = await Confirm('Delete everything?').prompt(interaction)
if confirm:
await interaction.send('deleted...')我建议阅读上面链接的文档来理解差异。
https://stackoverflow.com/questions/73188805
复制相似问题