简体   繁体   中英

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. Sometimes after ~ 1hour, the bot doesn't register reactions anymore. 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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM