Skip to content

feat: components v2 & View improvements #2707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 245 commits into
base: master
Choose a base branch
from

Conversation

NeloBlivion
Copy link
Member

@NeloBlivion NeloBlivion commented Feb 6, 2025

Summary

Soon




Information

  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed).
  • This PR is not a code change (e.g. documentation, README, typehinting,
    examples, ...).

Checklist

  • I have searched the open pull requests for duplicates.
  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • If type: ignore comments were used, a comment is also left explaining why.
  • I have updated the changelog to include these changes.

Reference:

message-components-v2-text-display
message-components-v2-container
message-components-v2-file
message-components-v2-media-gallery
message-components-v2-section
message-components-v2-separator

@Lulalaby Lulalaby added discord limitation Limitation imposed by discord priority: medium Medium Priority status: in progress Work in Progess feature Implements a feature upcoming discord feature Involves a feature not yet fully released by Discord labels Feb 6, 2025
@Lulalaby Lulalaby added this to the v2.7 milestone Feb 6, 2025
NeloBlivion and others added 21 commits June 29, 2025 14:35
Co-authored-by: plun1331 <plun1331@gmail.com>
Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com>
Signed-off-by: UK <41271523+NeloBlivion@users.noreply.github.com>
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com>
Signed-off-by: UK <41271523+NeloBlivion@users.noreply.github.com>
Co-authored-by: plun1331 <plun1331@gmail.com>
Signed-off-by: UK <41271523+NeloBlivion@users.noreply.github.com>
@Paillat-dev
Copy link
Contributor

@NeloBlivion I think something broke with your recent pushes:

if payload["content"] or payload["embeds"]

in ``discord/webhooks/_async.py`

Is causing:

KeyError: 'content'
  File "discord/commands/core.py", line 138, in wrapped
    ret = await coro(arg)
  File "discord/commands/core.py", line 1078, in _invoke
    await self.callback(self.cog, ctx, **kwargs)
  File "src/extensions/chatcop/cogs/admin/__init__.py", line 260, in view
    await ctx.respond(view=view, ephemeral=True, allowed_mentions=discord.AllowedMentions.none())
  File "discord/ext/bridge/context.py", line 92, in respond
    return await self._respond(*args, **kwargs)
  File "discord/ext/bridge/context.py", line 145, in _respond
    return await self._get_super("respond")(*args, **kwargs)
  File "discord/interactions.py", line 694, in respond
    return await self.followup.send(*args, **kwargs)
  File "discord/webhook/async_.py", line 1822, in send
    params = handle_message_parameters(
  File "discord/webhook/async_.py", line 673, in handle_message_parameters
    if payload["content"] or payload["embeds"]:

@@ -69,12 +105,15 @@ class Component:
----------
type: :class:`ComponentType`
The type of component.
id: :class:`int`
The component's ID. If not provided by the user, it is automatically incremented.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The component's ID. If not provided by the user, it is automatically incremented.
The component's ID. If not provided by the user, it is set sequentially by Discord.
The ID `0` is treated as if no ID was provided.

id: NotRequired[int]


class ActionRow(BaseComponent):
type: Literal[1]
components: list[Component]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
components: list[Component]
components: list[ButtonComponent, InputText, SelectMenu]

Or make an AllowedActionRowComponent class like done with container.

self.children: list[Component] = [
_component_factory(d) for d in data.get("components", [])
]

@property
def width(self):
"""Return the total item width that this action row uses."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"""Return the total item width that this action row uses."""
"""Return the sum of the children's widths."""

class Section(Component):
"""Represents a Section from Components V2.

This is a component that groups other components together.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This is a component that groups other components together.
This is a component that groups other components together with an additional component to the right as the accessory.

description: Optional[:class:`str`]
The thumbnail's description, up to 1024 characters.
spoiler: Optional[:class:`bool`]
Whether the thumbnail is a spoiler.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Whether the thumbnail is a spoiler.
Whether the thumbnail has the spoiler overlay.

"""

if len(self.items) >= 10:
raise ValueError("maximum number of children exceeded")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
raise ValueError("maximum number of children exceeded")
raise ValueError("maximum number of items exceeded")

description: Optional[:class:`str`]
The thumbnail's description, up to 1024 characters.
spoiler: Optional[:class:`bool`]
Whether the thumbnail is a spoiler. Defaults to ``False``.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Whether the thumbnail is a spoiler. Defaults to ``False``.
Whether the thumbnail has the spoiler overlay. Defaults to ``False``.


def enable_all_items(self, *, exclusions: list[Item] | None = None) -> Self:
"""
Enables all buttons and select menus in the container.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Enables all buttons and select menus in the container.
Enables all buttons and select menus in the section.

description: Optional[:class:`str`]
The thumbnail's description, up to 1024 characters.
spoiler: Optional[:class:`bool`]
Whether the thumbnail is a spoiler. Defaults to ``False``.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Whether the thumbnail is a spoiler. Defaults to ``False``.
Whether the thumbnail has the spoiler overlay. Defaults to ``False``.


@property
def spoiler(self) -> bool:
"""Whether the thumbnail is a spoiler. Defaults to ``False``."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"""Whether the thumbnail is a spoiler. Defaults to ``False``."""
"""Whether the thumbnail has the spoiler overlay. Defaults to ``False``."""

This only fires for a view if you did not define its :func:`~discord.ui.View.on_error`.
"""

print(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should consider using something else than print

This only fires for a modal if you did not define its :func:`~discord.ui.Modal.on_error`.
"""

print(f"Ignoring exception in modal {interaction.modal}:", file=sys.stderr)
Copy link
Contributor

Choose a reason for hiding this comment

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

Idem

r._state = state
return r

def to_dict(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def to_dict(self):
def to_dict(self) -> dict[str, str]:

r.media = media
return r

def to_dict(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def to_dict(self):
def to_dict(self) -> dict[str, str | dict[str, str] | bool]:

or just dict[str, Any]

Copy link
Contributor

@Icebluewolf Icebluewolf left a comment

Choose a reason for hiding this comment

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

I cannot for the life of me figure out how to suggest a change to this line.
https://github.com/Pycord-Development/pycord/pull/2707/files#diff-5894d281c8e052e9224fdf3643f8260c0c0a5fa59acbb808ba7faf54bede6ee9R1773
But just add "dispatchable" before "view"
Line 1773 of webhook/async_.py

@Lulalaby
Copy link
Member

yeah that line is not part of the actual diff so u cant suggest there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discord limitation Limitation imposed by discord feature Implements a feature hold: changelog This pull request is missing a changelog entry priority: medium Medium Priority status: in progress Work in Progess upcoming discord feature Involves a feature not yet fully released by Discord
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.