-
-
Notifications
You must be signed in to change notification settings - Fork 477
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
base: master
Are you sure you want to change the base?
feat: components v2 & View
improvements
#2707
Conversation
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>
@NeloBlivion I think something broke with your recent pushes: if payload["content"] or payload["embeds"] in ``discord/webhooks/_async.py` Is causing:
|
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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``.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""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( |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def to_dict(self): | |
def to_dict(self) -> dict[str, str]: |
r.media = media | ||
return r | ||
|
||
def to_dict(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def to_dict(self): | |
def to_dict(self) -> dict[str, str | dict[str, str] | bool]: |
or just dict[str, Any]
There was a problem hiding this 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
yeah that line is not part of the actual diff so u cant suggest there |
Summary
Soon
Temporary reference: https://github.com/Lulalaby/discord-api-docs/blob/comp_v2/docs/interactions/Message_Components.md#v2-components
Official PR for the docs is available now at Components v2 discord/discord-api-docs#7487
Information
examples, ...).
Checklist
type: ignore
comments were used, a comment is also left explaining why.Reference: