🐛 Fix color_select.py example not changing embed color

This commit is contained in:
2024-08-03 15:59:36 +02:00
parent f1a8c2e31d
commit 191d1d2d9b
7 changed files with 40 additions and 9 deletions

0
examples/__init__.py Normal file
View File

View File

@@ -1,9 +1,9 @@
# ruff: noqa: INP001
import os
import discord
from dotenv import load_dotenv
from pycord_reactive_views import ReactiveSelect, ReactiveValue, ReactiveView
from typing_extensions import override
load_dotenv()
@@ -71,6 +71,7 @@ class ColourSelector(ReactiveView):
async def _colour_select_callback(self, interaction: discord.Interaction) -> None:
await interaction.response.defer()
self.colour = self.colour_select.values[0] # pyright: ignore[reportAttributeAccessIssue]
self.shade = colors[self.colour][0]
await self.update()
async def _shade_select_callback(self, interaction: discord.Interaction) -> None:
@@ -79,6 +80,7 @@ class ColourSelector(ReactiveView):
self.shade = discord.Colour(selected_shade)
await self.update()
@override
async def _get_embed(self) -> discord.Embed | None:
return discord.Embed(
title=f"{self.colour.capitalize()} {self.shade}",

View File

@@ -1,4 +1,3 @@
# ruff: noqa: INP001
import os
import discord
@@ -26,7 +25,7 @@ class Counter(ReactiveView):
self.reset_button = ReactiveButton(
label="Reset",
style=discord.ButtonStyle.danger,
disabled=ReactiveValue(lambda: self.counter == 0, True),
disabled=ReactiveValue(lambda: self.counter == 0, default=True),
)
self.counter_button.callback = self._increment
self.reset_button.callback = self._reset