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)```