[英]Pycord/discord.py indefinitely await reponse
When I create a button and handle the callback or send a message and await a reaction in discord with my python bot, this seems to be limited in time.当我创建一个按钮并处理回调或发送消息并等待与我的 python 机器人不一致的反应时,这似乎在时间上是有限的。 Sometimes after ~ 1hour, the bot doesn't register reactions anymore.有时大约 1 小时后,机器人不再记录反应。 For sure once I restart the bot, the connection is lost and it won't register the interaction anymore.当然,一旦我重新启动机器人,连接就会丢失,它不会再注册交互了。
However, I have seen bots in discord that always react to a button, no matter how long ago that button was created.但是,我看到不和谐的机器人总是对按钮做出反应,无论该按钮是多久之前创建的。 Is there a way to achieve this?有没有办法做到这一点? Do I have to periodically "reconnect" the bot to the buttons it created?我是否必须定期将机器人“重新连接”到它创建的按钮?
Simple example:简单的例子:
@client.command()
async def create(ctx, nome):
def check(m):
return ctx.author == m.author #To make sure it is the only message author is getting
embed = discord.Embed(title='Criar Venda', description='Selecione umas das opções!', color=discord.Color.blue())
butto = Button(label='Titulo', style=discord.ButtonStyle.green)
view = View()
view.add_item(butto)
async def callback1(interaction: discord.Interaction):
member = interaction.user
await interaction.response.send_message("Titulo?")
msg = await client.wait_for('message', timeout=60.0, check=check)
titulo_embed = msg.content
await ctx.send(f'Titulo do Embed: {titulo_embed}')
butto.callback = callback1
await ctx.send(embed=embed, view=view)
```
-> In this example the bot won't react to the button click anymore after some time has passed or I restarted the bot.
像这样使用 custom_id 分配按钮。
butto = Button(label='Titulo', style=discord.ButtonStyle.green, custom_id="butto")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.