Skip to content

Conversation

@Paillat-dev
Copy link
Member

@Paillat-dev Paillat-dev commented Aug 3, 2025

ok now that this is starting to become more concrete, here is some info:

This pull request refactors rewrites py-cord's Components and Modals interface from the ground up. discord.ui has been removed entirely and replaced by top-level classes available in discord directly.

Since View has been removed, purposefully, py-cord becomes entirely stateless, which essentially means that all "views" are now persistent.

Caution

This removes ext.pages entirely since it cannot fundamentally be updated to work with the new design.

The API works as follows:

Components Example (click to open)
def build_container(secret_message: str) -> Container:
    return Container(
        ActionRow(
            Button(
                style=ButtonStyle.primary,
                label="Click me! I'll tell you a secret",
                custom_id=f"v1:hello_button_{secret_message}",
                emoji=PartialEmoji(name="🤫"),
            )
        ),
        id=3,
    )


@bot.command()
async def secret(ctx: ApplicationContext, secret_message: str) -> None:
    await ctx.respond(
        components=[build_container(secret_message)],
    )

def hello_button_predicate(custom_id: str) -> bool:
   return custom_id.startswith("v1:hello_button_") 

@bot.component_listener(hello_button_predicate)
async def hello_button(interaction: ComponentInteraction[Button]) -> None:
    secret_message = interaction.custom_id.split("hello_button_")[1]
    await interaction.respond(
        f"Hello {interaction.user.name}! The secret message is: ||{secret_message}||", ephemeral=True
    )

If you want to understand the api in more detail, you can open the latest readthedocs build and take a look at:

  • discord.Component
  • discord.ComponentsSequence
  • discord.Bot.component_listener
  • discord.Bot.add_component_listener
  • discord.Bot.remove_component_listener

You can also take a look at the diff of the CHANGELOG-V3.md file

Additionally, this implements stuff of the new discord Modals API like shown below:

Modals Example (click to open)
from discord import components
SECRET_MODAL = components.Modal(
    components.Label(
        label="Secret Message",
        component=components.TextInput(
            style=discord.TextInputStyle.long,
            custom_id="v1:secret_input",
            placeholder="Enter your secret message here...",
            required=True,
        ),
    ),
    Label(
        label="Favourite Color",
        component=components.StringSelectMenu(
            options=[
                components.SelectOption(label="Red", value="red"),
                components.SelectOption(label="Green", value="green"),
                components.SelectOption(label="Blue", value="blue"),
            ],
            required=False,
            custom_id="v1:color_select",
            min_values=1,
            max_values=1
        )
    ),
    components.Label(
        label="Your favourite user",
        description="Please select your favourite user in this server",
        component=components.UserSelectMenu(
            custom_id="v1:user_select",
            min_values=1,
            max_values=4,
            required=True,
            default_values=[components.DefaultSelectOption(856780995629154305, "user"), components.DefaultSelectOption(707196665668436019, "user")]
        )
    ),
    components.TextDisplay(
        content="By submitting this form, you acknowledge that the information provided is accurate and truthful to the best of your knowledge."
    ),
    title="Secret Message Input",
    custom_id=f"v1:secret_modal",
)


@bot.command(integration_types={components.IntegrationType.guild_install, components.IntegrationType.user_install}, context={components.InteractionContextType.guild, components.InteractionContextType.bot_dm, components.InteractionContextType.private_channel})
async def secret(ctx: discord.ApplicationContext) -> None:
    await ctx.send_modal(SECRET_MODAL)

@bot.modal_listener("v1:secret_modal")
async def hello_button(
        interaction: discord.ModalInteraction[
            components.PartialLabel[components.PartialTextInput], components.PartialLabel[components.PartialStringSelect], components.PartialLabel[components.PartialUserSelect], components.PartialTextDisplay
        ],
) -> None:
    _ = await interaction.respond(
        components=[
            components.Container(
                components.TextDisplay("## Your secret message has been received!"),
                components.TextDisplay(f"**Secret Message:** {interaction.components[0].component.value}"),
                components.TextDisplay(
                    f"**Favourite Color:** {interaction.components[1].component.values[0]}"
                ),
                components.TextDisplay(
                    f"**Favourite Users:** {', '.join([f'<@{option}>' for option in interaction.components[2].component.values])}"
                ),
            )
        ],
        allowed_mentions=AllowedMentions.none(),
    )

This also removes multiple long deprecated methods / properties from interactions.py

depends on #44
depends on #62

fixes: #11

Paillat-dev and others added 30 commits May 29, 2025 20:25
* Start migration to uv

* Setup ruff and hatch

* Change pre-commit to use ruff

* Format with ruff

* Fix mistake

* Add dev deps

* Change workflows to use uv and ruff

* ➕ Add colorlog and remove requirements folder and fix build

* 💚 Fix sphinx build ?

* 🐛 Add __version.py for version management and update import in __init__.py

* ✏️ Update lib-checks.yml to run ruff on ubuntu-latest

* 🐛 Update lib-checks.yml to run mypy with uv

* 🔥 Delete MANIFEST.in

* ✨ Enhance lib-checks.yml to include ruff formatter check

* ♻️ Refactor pyproject.toml and uv.lock to use optional-dependencies for voice and speed
Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>
* chore: Update localization workflows to use 'uv' for dependency management

* chore: refactor Read the Docs configuration to use uv
* change default nsfw to false

* cl

* localizations

* :=

* style(pre-commit): auto fixes from pre-commit.com hooks

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Signed-off-by: Hema2 <49586027+Hema2-official@users.noreply.github.com>
Co-authored-by: Lala Sabathil <lala@pycord.dev>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…h-version-bumps group (Pycord-Development#2783)

chore(deps): bump typing-extensions in the patch-version-bumps group

Bumps the patch-version-bumps group with 1 update: [typing-extensions](https://github.com/python/typing_extensions).


Updates `typing-extensions` from 4.13.1 to 4.13.2
- [Release notes](https://github.com/python/typing_extensions/releases)
- [Changelog](https://github.com/python/typing_extensions/blob/main/CHANGELOG.md)
- [Commits](python/typing_extensions@4.13.1...4.13.2)

---
updated-dependencies:
- dependency-name: typing-extensions
  dependency-version: 4.13.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: patch-version-bumps
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* feat: add created_at property to Interaction for message creation time

* Update CHANGELOG.md

* Update discord/interactions.py

Co-authored-by: UK <41271523+NeloBlivion@users.noreply.github.com>
Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* Update CHANGELOG.md

Co-authored-by: DA344 <108473820+DA-344@users.noreply.github.com>
Signed-off-by: Lala Sabathil <aiko@aitsys.dev>

---------

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>
Signed-off-by: Lala Sabathil <aiko@aitsys.dev>
Co-authored-by: UK <41271523+NeloBlivion@users.noreply.github.com>
Co-authored-by: Lala Sabathil <aiko@aitsys.dev>
Co-authored-by: DA344 <108473820+DA-344@users.noreply.github.com>
…62.6,<=80.8.0 (Pycord-Development#2786)

chore(deps): update setuptools requirement

Updates the requirements on [setuptools](https://github.com/pypa/setuptools) to permit the latest version.
- [Release notes](https://github.com/pypa/setuptools/releases)
- [Changelog](https://github.com/pypa/setuptools/blob/main/NEWS.rst)
- [Commits](pypa/setuptools@v72.2.0...v80.8.0)

---
updated-dependencies:
- dependency-name: setuptools
  dependency-version: 80.8.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…cord-Development#2731)

* 🔥 Remove deprecated support for Option in bridge commands

* 📝 CHANGELOG.md

* ♻️ Better logic

---------

Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
…ord-Development#2761)

* 🐛 Handle `thread_name` in `handle_message_parameters` to allow sending to thread with multipart

* 📝 CHANGELOG.md

* Update CHANGELOG.md

Co-authored-by: plun1331 <plun1331@gmail.com>
Signed-off-by: Paillat <jeremiecotti@ik.me>

---------

Signed-off-by: Paillat <me@paillat.dev>
Signed-off-by: Paillat <jeremiecotti@ik.me>
Co-authored-by: plun1331 <plun1331@gmail.com>
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
…2798)

* fix: add BanEntry to __all__ exports in guild.py

* Hold on

Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>

---------

Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
…nt#2796)

* Update CHANGELOG.md

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* sync with pycord

* fix: update Item type hints to Item[View] in view.py

* fix: update Item type hints to use TypeVar[V] in view.py

---------

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
…>=6.2,<=8.3.1 (Pycord-Development#2785)

chore(deps): update setuptools-scm requirement

Updates the requirements on [setuptools-scm](https://github.com/pypa/setuptools-scm) to permit the latest version.
- [Release notes](https://github.com/pypa/setuptools-scm/releases)
- [Changelog](https://github.com/pypa/setuptools-scm/blob/main/CHANGELOG.md)
- [Commits](pypa/setuptools-scm@v8.1.0...v8.3.1)

---
updated-dependencies:
- dependency-name: setuptools-scm
  dependency-version: 8.3.1
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…ycord-Development#2784)

Updates the requirements on [pylint](https://github.com/pylint-dev/pylint) to permit the latest version.
- [Release notes](https://github.com/pylint-dev/pylint/releases)
- [Commits](pylint-dev/pylint@v3.3.6...v3.3.7)

---
updated-dependencies:
- dependency-name: pylint
  dependency-version: 3.3.7
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
updates:
- [github.com/asottile/pyupgrade: v3.19.1 → v3.20.0](asottile/pyupgrade@v3.19.1...v3.20.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* 🐛 Fix `dataclasses.field` can't be reused

* 📝 CHANGELOG.md

* Update CHANGELOG.md

Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>

* ♻️ Move `_missing_field_factory` to flags.py and remove incorrect comment

---------

Signed-off-by: Paillat <me@paillat.dev>
Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
…-version-bumps group (Pycord-Development#2805)

ci(deps): bump crowdin/github-action in the patch-version-bumps group

Bumps the patch-version-bumps group with 1 update: [crowdin/github-action](https://github.com/crowdin/github-action).


Updates `crowdin/github-action` from 2.7.0 to 2.7.1
- [Release notes](https://github.com/crowdin/github-action/releases)
- [Commits](crowdin/github-action@v2.7.0...v2.7.1)

---
updated-dependencies:
- dependency-name: crowdin/github-action
  dependency-version: 2.7.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: patch-version-bumps
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
…ycord-Development#2774)

* handle emoji_lib

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* style(pre-commit): auto fixes from pre-commit.com hooks

* Update CHANGELOG.md

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* usage of dismoji

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* Update _.txt

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* removal of dismoji

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* Update _.txt

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* style(pre-commit): auto fixes from pre-commit.com hooks

* NEED HELP 

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* style(pre-commit): auto fixes from pre-commit.com hooks

* Update partial_emoji.py

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* style(pre-commit): auto fixes from pre-commit.com hooks

* Add files via upload

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* style(pre-commit): auto fixes from pre-commit.com hooks

* Update partial_emoji.py

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* Update discord/partial_emoji.py

Co-authored-by: plun1331 <plun1331@gmail.com>
Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* feature(partial_emoji): support :name: and name

* fix(partial_emoji): remove unnecessary data variable after processing emojis

* Update partial_emoji.py

Co-authored-by: Paillat <jeremiecotti@ik.me>
Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* reduce emoji.json weight

* Update emojis.json

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* refactor: replace Path with importlib.resources for loading emojis.json

* Update emojis.json

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

---------

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: plun1331 <plun1331@gmail.com>
Co-authored-by: Paillat <jeremiecotti@ik.me>
Co-authored-by: Lala Sabathil <lala@pycord.dev>
…m_str" (Pycord-Development#2814)

Revert "fix: support emoji aliases like `:smile:` in PartialEmoji.from_str (#…"

This reverts commit 735673b.
Signed-off-by: Paillat-dev <paillat@pycord.dev>
Signed-off-by: Paillat-dev <paillat@pycord.dev>
Signed-off-by: Paillat-dev <paillat@pycord.dev>
Signed-off-by: Paillat-dev <paillat@pycord.dev>
Signed-off-by: Paillat-dev <paillat@pycord.dev>
Signed-off-by: Paillat-dev <paillat@pycord.dev>
Signed-off-by: Paillat-dev <paillat@pycord.dev>
Signed-off-by: Paillat-dev <paillat@pycord.dev>
Signed-off-by: Paillat-dev <paillat@pycord.dev>
Signed-off-by: Paillat-dev <paillat@pycord.dev>
Signed-off-by: Paillat-dev <paillat@pycord.dev>
Signed-off-by: Paillat-dev <paillat@pycord.dev>
@Paillat-dev Paillat-dev requested a review from Copilot October 21, 2025 22:48
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 92 out of 93 changed files in this pull request and generated 7 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Paillat-dev and others added 6 commits October 22, 2025 01:04
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Paillat <jeremiecotti@ik.me>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Paillat <jeremiecotti@ik.me>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Paillat <jeremiecotti@ik.me>
Copy link

@Lumabots Lumabots left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment + type strict that i'll do once those are solved

@property
def emoji(self) -> PartialEmoji | None:
"""The emoji of the option, if available."""
return self._emoji
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_emoji is never set, pretty sure there is some issue inside the init with self.emoji = emoji (since emoji is a property)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is set when in the init it sets self.emoji, that calls the @emoji.setter which itself sets _emoji

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didnt know about this behavior then its good !

"min_values": self.min_values,
"max_values": self.max_values,
"required": self.required,
"id": self.id,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id is typed as int | None however FileUploadPayload id cant be none as its a literal 19, maybe there is some thing to look for here (same for from payload etc)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THose are all to be ignored, id None can be sent to discord and will be handled as 0, it just will always be an int when recieved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont get the point of the id as from the payload it can only be 19 since its the file upload one
So why are we letting the user change it ?
(mb just realize that type is the 19, id is something else...)
And so why are we not putting it into the payload as notrequired ?

Could not access item in TypedDict
  "id" is not a required key in "FileUpload", so access may result in runtime

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it is always there when we get the payload

Copy link

@Lumabots Lumabots Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then why not add it to the payload ?
Screenshot 2025-11-10 at 14 51 14

Because it is always there when we get the payload

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is on BaseComponent

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but shouldnt it be override since it will always be and so required?

Im thinking about something like this

class FileUpload(BaseComponent):
    id: int # Will be 0 if not provided (and not required)
    type: Literal[19]
    custom_id: str
    min_values: NotRequired[int]
    max_values: NotRequired[int]
    required: NotRequired[bool]

Paillat-dev and others added 2 commits November 8, 2025 21:10
Co-authored-by: Lumouille <144063653+Lumabots@users.noreply.github.com>
Signed-off-by: Paillat <jeremiecotti@ik.me>
Signed-off-by: Paillat-dev <paillat@pycord.dev>
@Paillat-dev Paillat-dev requested a review from Lumabots November 8, 2025 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

don't-merge DO NOT MERGE enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a low-level components api Remove views

9 participants