pycord在重新启动后无需重新发送或编辑消息即可获得交互



我目前正在为我的服务器开发一个self-roles机器人程序,每次我重新启动机器人程序时都会遇到这个问题,必须编辑或重新发送带有按钮的消息才能使按钮再次工作,否则它只会说"这种交互失败了";。

这是我的按钮的代码:

embed = discord.Embed(
description="Title"
"Description"
)
requestbutton = discord.ui.Button(
label="make a request"
)
async def requestcallback(interaction: discord.Interaction):
modal = RequestModal()
await interaction.response.send_modal(modal)
requestbutton.callback = requestcallback
view = discord.ui.View()
view.timeout = None
view.add_item(requestbutton)

await requestschannel.send(embed=embed, view=view)

重新启动后,是否可以在不重新发送或编辑消息的情况下让按钮再次工作?

我使用PersistentViews修复了它。

示例位于:https://github.com/Pycord-Development/pycord/blob/master/examples/views/persistent.py

最新更新