#🔒 Disable button after 10 sec no activity | disnake

8 messages · Page 1 of 1 (latest)

lethal mortar
#

I've got a command with an active button. I want to disable a button if there is no activity with it. For example: I used command /bank app and for 10 second I don't use the button. If there is no activity, the button should be disabled.

Code:

class MyView(disnake.ui.View):
    def __init__(self):
        super().__init__(timeout=10)

    @disnake.ui.button(emoji="💳", label="Банківська картка", disabled=False)
    async def button_callback_1_active(self, button, interaction):
        with open('data/economy/economy.json', 'r', encoding='utf-8') as f:
            data = json.load(f)
        
        font_type = 'fonts/AABebasNeue.ttf'
        bank_card = Image.open('images/banking system/template_card.png')
        draw = ImageDraw.Draw(bank_card)
        
        emb = disnake.Embed(title=f"💳Банківський рахунок", colour=disnake.Color.blue(), timestamp=interaction.created_at)
        emb.set_image(file=disnake.File('images/banking system/bank_card.png'))
        emb.set_footer(text = f"{config.BY_LINE}", icon_url = bot.user.display_avatar.url)
        await interaction.response.edit_message(embed=emb)

        @bot.event()
        async def on_timeout(self):
            for item in self.children:
                item.disabled = True
            await self.message.edit(view=self)
            print(1)


 @bank.sub_command()
    async def app(self, ctx):
        view = MyView()

        emb = disnake.Embed(title="Банківська система", description="Вітаємо в **Банку «TarasBot»**! Виберіть подальшу операцію для взаємодії з банком ↓↓↓", colour=disnake.Color.blue(), timestamp=ctx.created_at)
        emb.set_footer(text=f"{config.BY_LINE}", icon_url=bot.user.display_avatar.url)
        await ctx.send(embed=emb, view=view)```
hushed wharfBOT
#

@lethal mortar

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

lethal mortar
#

In this code, the button will be inactive after 10 seconds. It will show the error after 10 second timer

#

But I have no idea how to do this disabled button after 10sec no activity

harsh rose
lethal mortar
hushed wharfBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.