Discord机器人按钮报错:'Button'对象无'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
相关产品推荐
相关产品推荐

