属性错误:“上下文”对象没有属性“响应”

问题描述 投票:0回答:1

我制作了我的不和谐机器人,并在模态上发出报告命令。

class ReportModal(discord.ui.Modal, title="Репорт юзер"):
    user_name = discord.ui.TextInput(label="Юзер дискорд наме", placeholder="eg. Jgfhfhjfkfk#0000", required=True, max_length=10000, style=discord.TextStyle.short)
    user_id = discord.ui.TextInput(label="Юзер дискорд наме2", placeholder="eg. Jgfhfhjfkfk#0000", required=True, max_length=10000, style=discord.TextStyle.long)
@bot.command(name="report", description="Репорт юзер")#name="report", description="Репорт юзер"
async def report(interaction: discord.Interaction):
    modal = ReportModal()
    await interaction.response.send_modal(modal)

错误

  File "/home/container/.local/lib/python3.11/site-packages/discord/ext/commands/core.py", line 235, in wrapped
    ret = await coro(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/container/main.py", line 26, in report
    await interaction.response.send_modal(modal)
          ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Context' object has no attribute 'response'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/container/.local/lib/python3.11/site-packages/discord/ext/commands/bot.py", line 1350, in invoke
    await ctx.command.invoke(ctx)
  File "/home/container/.local/lib/python3.11/site-packages/discord/ext/commands/core.py", line 1029, in invoke
    await injected(*ctx.args, **ctx.kwargs)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/container/.local/lib/python3.11/site-packages/discord/ext/commands/core.py", line 244, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Context' object has no attribute 'response'
python discord.py
1个回答
0
投票

您正在将“经典命令”与新的“应用程序命令”(斜杠命令)混合在一起。

尝试使用

@bot.tree.command
代替
@bot.command

不要忘记使用 await bot.tree.sync()

同步
您的命令!


旧命令获取

Context
对象作为第一个参数。新的应用程序命令获取一个
Interaction
对象。

© www.soinside.com 2019 - 2024. All rights reserved.