【问题标题】:Buttons not working in Discord Py 2.0. When you click on the button, it displays the error below按钮在 Discord Py 2.0 中不起作用。当您单击按钮时,它会显示以下错误
【发布时间】:2023-02-04 05:20:33
【问题描述】:

这是代码:

class Buttons(discord.ui.View):
    def __init__(self, *, timeout=180):
        super().__init__(timeout=timeout)

    @discord.ui.button(label="Blurple Button", style=discord.ButtonStyle.blurple)  # or .primary
    async def blurple_button(self, button : discord.ui.Button, interaction: discord.Interaction):
        print('1')
        button.disabled = True
        await interaction.response.edit_message(view=self)

这是错误:

机器人连接 1个 2023-02-03 23:47:15 错误 discord.ui.view 忽略项目视图中的异常 <Button style=<ButtonStyle.primary: 1> url=None disabled=False label='Blurple Button' emoji=None row=无> 追溯(最近一次通话): 文件“D:\Andrej\3.Project\venv\Lib\site-packages\discord\ui\view.py”,第 425 行,在 _scheduled_task 中 > 等待 item.callback(交互) 文件“D:\Andrej\3.Project\Ecumonopolis 1.0\ecumenopolis ORM.py”,第 506 行,在 blurple_button 中 > button.disabled = True ^^^^^^^^^^^^^^^ AttributeError:“交互”对象没有属性“已禁用”

请帮帮我。并帮我找出 Discord Py 2.0 中的按钮 先感谢您!

请帮帮我。并帮我找出 Discord Py 2.0 中的按钮 先感谢您!

【问题讨论】:

    标签: discord discord.py discord-buttons


    【解决方案1】:
    button.disabled = True
    AttributeError: 'Interaction' object has no attribute 'disabled'
    

    正如错误告诉您的那样,您的button 参数实际上是一个Interaction,反之亦然。你的论点是错误的。

    有需要的official examples for views & buttons

    您帖子中的标签还表明您正在使用第三方按钮包。没必要,一切都内置在discord.py中。

    【讨论】:

      猜你喜欢
      • 2022-10-31
      • 1970-01-01
      • 2020-01-10
      • 1970-01-01
      • 1970-01-01
      • 2021-07-29
      • 1970-01-01
      • 2022-11-04
      • 1970-01-01
      相关资源
      最近更新 更多