[Python] Discord: embed - auto reset to inital embed

Discussão em 'Python' iniciado por Stack, Fevereiro 20, 2025.

  1. Stack

    Stack Membro Participativo

    I am currently looking for a way to auto reset the embed in a Discord python bot. This is my code. It works fine the very first time a user clicks on a category. The second time it won't refresh anymore. How can I fix that?

    class AutoResetView(discord.ui.View):
    def __init__(self, initial_embed: discord.Embed, reset_time: int = 300):
    super().__init__(timeout=None)
    self.message = None
    self.initial_embed = initial_embed
    self.reset_time = reset_time
    self._reset_task = None

    async def on_timeout(self):
    await self.reset_to_initial_embed()

    async def reset_to_initial_embed(self):
    if self.message:
    await self.message.edit(embed=self.initial_embed, view=self)

    async def start_auto_reset(self):
    await asyncio.sleep(self.reset_time)
    await self.reset_to_initial_embed()

    def set_message(self, message):
    self.message = message

    async def on_select(self, interaction: discord.Interaction):
    print("Auswahl getroffen!")
    await self.reset_to_initial_embed()
    await self.start_auto_reset()

    class SummonView(AutoResetView):
    def __init__(self):
    initial_embed = discord.Embed(title="TITLE", description="DESCRIPTION", color=COLOR)
    super().__init__(initial_embed)
    self.add_item(SummonDropdown())

    async def send_view(self, channel: discord.TextChannel):
    self.message = await channel.send(embed=self.initial_embed, view=self)
    self.set_message(self.message)
    await self.start_auto_reset()


    @bot.command()
    async def send_summon(ctx):
    summon_view = SummonView()
    await summon_view.send_view(ctx.channel)

    Continue reading...

Compartilhe esta Página