feat: Radio Groups & Checkboxes#3073
feat: Radio Groups & Checkboxes#3073NeloBlivion wants to merge 45 commits intoPycord-Development:masterfrom
Conversation
|
Thanks for opening this pull request! This pull request can be checked-out with: git fetch origin pull/3073/head:pr-3073
git checkout pr-3073This pull request can be installed with: pip install git+https://github.com/Pycord-Development/pycord@refs/pull/3073/head |
Signed-off-by: Lala Sabathil <aiko@aitsys.dev>
Signed-off-by: Lala Sabathil <aiko@aitsys.dev>
Signed-off-by: Lala Sabathil <aiko@aitsys.dev>
Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com> Signed-off-by: Nelo <41271523+NeloBlivion@users.noreply.github.com>
Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com> Signed-off-by: Nelo <41271523+NeloBlivion@users.noreply.github.com>
|
todo:
|
Test Codeimport logging
import os
from typing import override
from dotenv import load_dotenv
import discord
load_dotenv()
logging.basicConfig(level=logging.INFO)
bot = discord.Bot(intents=discord.Intents.all())
class WowModal(discord.ui.DesignerModal):
def __init__(self):
super().__init__(timeout=None, title="PYCORD IS AMAZING")
self.add_item(
discord.ui.Label(
label="Enable",
description="Enable or disable the bot",
item=discord.ui.Checkbox(default=False),
)
)
@override
async def callback(self, interaction: discord.Interaction):
await interaction.respond("Button clicked!")
@bot.slash_command(name="test_modalsv5")
async def test_modal(ctx: discord.ApplicationContext):
await ctx.send_modal(WowModal())
bot.run(os.getenv("TOKEN_2"))Fyi I encounter this: |
|
probably done? |
| if self.default is not None: | ||
| payload["default"] = self.default |
There was a problem hiding this comment.
Can't be None, should be in the initial payload.
| def __repr__(self) -> str: | ||
| attrs = " ".join( | ||
| f"{key}={getattr(self, key)!r}" for key in self.__item_repr_attributes__ | ||
| ) | ||
| return f"<{self.__class__.__name__} {attrs}>" |
There was a problem hiding this comment.
Why does it redefine this? It's handled by Item.
| custom_id: Optional[:class:`str`] | ||
| The custom ID of the radio group that gets received during an interaction. | ||
| options: List[:class:`RadioGroupOption`] | ||
| A list of options that can be selected in this group. |
There was a problem hiding this comment.
Could mention that this can only contain min 2 and max 10 items.
| def __repr__(self) -> str: | ||
| attrs = " ".join( | ||
| f"{key}={getattr(self, key)!r}" for key in self.__item_repr_attributes__ | ||
| ) | ||
| return f"<{self.__class__.__name__} {attrs}>" |
| def __repr__(self) -> str: | ||
| attrs = " ".join( | ||
| f"{key}={getattr(self, key)!r}" for key in self.__item_repr_attributes__ | ||
| ) | ||
| return f"<{self.__class__.__name__} {attrs}>" |
| if len(value) > 10: | ||
| raise ValueError("you may only provide up to 10 options.") |
There was a problem hiding this comment.
Maybe also check the minimum (2)?
|
All version strings need changing to 2.8 too. |
| ) | ||
| if not isinstance(required, bool): | ||
| raise TypeError(f"required must be bool not {required.__class__.__name__}") # type: ignore | ||
| custom_id = os.urandom(16).hex() if custom_id is None else custom_id |
There was a problem hiding this comment.
Could be neat to have validation for there to be max(?) one option with default set to True
|
For the record, PR tested and everything seems to work fine other than obviously the comments |
discord/ui/file_upload.py
Outdated
| raise TypeError(f"required must be bool not {required.__class__.__name__}") # type: ignore | ||
| custom_id = os.urandom(16).hex() if custom_id is None else custom_id | ||
| self._attachments: list[Attachment] | None = None | ||
| self._attachments: list[Attachment] = [] |
There was a problem hiding this comment.
This was supposed to be None to differentiate between no interaction being recieved
There was a problem hiding this comment.
hmmm this is awkward, it seems the select default values pr changed to to an empty list in selects and so I went off of that (even though the docs weren't updated); i'll revert both changes instead for consistency.
Summary
Implements radio groups, checkbox groups, and checkboxes in modals

Alpha server only right now
Information
examples, ...).
Checklist
type: ignorecomments were used, a comment is also left explaining why.