Files
pycord-reactive-views/examples/test.py

20 lines
629 B
Python
Raw Normal View History

2024-07-30 12:48:04 +02:00
import discord
from pycord_reactive_views import ReactiveButton, ReactiveView
bot = discord.Bot()
class Counter(ReactiveView):
"""A simple counter view that increments a counter when a button is clicked."""
def __init__(self):
super().__init__()
self.counter = 0
self.counter_button = ReactiveButton(value=lambda: self.counter)
self.counter_button.callback = self._button_callback
self.add_item(self.counter_button)
async def _button_callback(self, interaction: discord.Interaction):
await interaction.response.defer()
self.counter += 1