首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“交互”对象没有属性'bot‘nextcord菜单

“交互”对象没有属性'bot‘nextcord菜单
EN

Stack Overflow用户
提问于 2022-08-01 04:20:53
回答 1查看 229关注 0票数 -1

我使用https://replit.com/为朋友构建一个不和谐的机器人,在我运行命令之前一切都很顺利,它给了我这个错误,我知道这意味着什么或者如何修复它,有人能帮忙吗?

错误:

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

发布于 2022-08-09 17:38:49

您需要将交互传递给交互kwarg。

斜杠命令为您提供一个名为Interaction的类型,而不是Context,因此不应该将其称为ctx

参见本例:https://menus.docs.nextcord.dev/en/stable/ext/menus/menu_examples/#slash-commands

代码语言:javascript
复制
@bot.slash_command()
async def slash_menu(interaction: nextcord.Interaction):
    await MySlashButtonMenu().start(interaction=interaction)

注意,在开始时,斜杠命令交互作为关键字参数传递给函数。

在您的示例中,您需要提示符来进行交互,并使用self.interaction来发送消息,而不是使用ctx或通道。

代码语言:javascript
复制
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...')

我建议阅读上面链接的文档来理解差异。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73188805

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档