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.
Assign the button with a custom_id like so.
butto = Button(label='Titulo', style=discord.ButtonStyle.green, custom_id="butto")