You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Discord机器人按钮报错:'Button'对象无'response'属性求助

问题解决:AttributeError: 'Button' object has no attribute 'response'

问题原因

discord.py 2.0及以上版本调整了按钮回调函数的参数顺序,你的代码里把button和interaction的位置写反了,导致实际调用时把Button对象当成了interaction来使用,自然找不到response属性。

修复后的代码

class MyView(View):  
    @discord.ui.button(label='Ping🏓', style=discord.ButtonStyle.red)
    async def ping_button_callback(self, interaction, button):
        await interaction.response.send_message(embed=pingembed)

额外注意事项

  • 确保pingembed变量已正确定义并传入,否则可能出现未定义相关错误
  • 若使用discord.py 2.0+版本,所有组件(按钮、选择菜单等)的回调函数参数顺序都需调整为self, interaction, component的格式

内容的提问来源于stack exchange,提问作者ySunsh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 11:10:36