簡體   English   中英

Pycord/discord.py 無限期等待響應

[英]Pycord/discord.py indefinitely await reponse

當我創建一個按鈕並處理回調或發送消息並等待與我的 python 機器人不一致的反應時,這似乎在時間上是有限的。 有時大約 1 小時后,機器人不再記錄反應。 當然,一旦我重新啟動機器人,連接就會丟失,它不會再注冊交互了。

但是,我看到不和諧的機器人總是對按鈕做出反應,無論該按鈕是多久之前創建的。 有沒有辦法做到這一點? 我是否必須定期將機器人“重新連接”到它創建的按鈕?

簡單的例子:

@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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM