Skip to content

Conversation

shiftinv
Copy link
Member

@shiftinv shiftinv commented Apr 18, 2025

Summary

discord/discord-api-docs@af1843d

This implements the new v2 components, including:

  • Section: displays a thumbnail or button next to some text
  • TextDisplay: plaintext, but as a component
  • MediaGallery: gallery/mosaic for up to 10 images
  • File: non-image attachments
  • Separator: vertical spacer/separator
  • Container: can be considered similar to an Embed

These new components are all non-interactive and intended for layout only, they are quite a bit more flexible than the previous content/embeds/attachments/components combo, and allow for much nicer looking/better structured messages.

Scope

I feel like it's worth clarifying that this is about as straightforward as the interface could be, only building on the existing implementation/functionality for components. There may very well be better ways (in terms of DX) to implement these components (namely, builder pattern, yippee), but I've considered this out of scope from the start.
I've intentionally not implemented support for the new components in Views, given the intended scope of this PR and the complexities that somehow integrating them would bring, especially since all of the components are non-interactive.
The goal with this PR was to get just about the most basic implementation going, any further work building on top of it will be in separate future PRs.

Example

code
components: Sequence[ui.UIComponent] = [
    ui.TextDisplay("test"),
    ui.Separator(),
    ui.Container(
        ui.TextDisplay("this is text inside a container"),
        ui.MediaGallery(
            disnake.MediaGalleryItem(
                media="https://placecats.com/900/600",
                description="a cool media item",
            ),
            disnake.MediaGalleryItem(
                media="https://placecats.com/800/600",
                description="more kitty",
                spoiler=True,
            ),
        ),
        ui.Section(
            ui.TextDisplay(
                "What an incredible media gallery.\nOkay, that's all the time I've got. I got to get back to playing Animal Crossing New Leaf on my Nintendo 3DS."
            ),
            accessory=ui.Thumbnail(
                media="https://i.kym-cdn.com/entries/icons/facebook/000/026/585/reggie_animalcrossingtour.jpg",
                description="desc",
            ),
        ),
        ui.Separator(spacing=disnake.SeparatorSpacingSize.large),
        ui.ActionRow(disnake.ui.ChannelSelect(placeholder="Choose a Channel!")),
        accent_colour=disnake.Colour(0xEE99CC),
        spoiler=False,
    ),
]

await inter.response.send_message(components=components, flags=disnake.MessageFlags(is_components_v2=True))

image

Checklist

  • If code changes were made, then they have been tested
    • I have updated the documentation to reflect the changes
    • I have formatted the code properly by running pdm lint
    • I have type-checked the code by running pdm pyright
  • 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, ...)

this enum isn't documented/named separately in the current release docs anyway, it was only part of the initial alpha types
…tch ActionRow

also sort attributes to have `children` first because it was driving me insane with
how inconsistent it turned out over time
@shiftinv shiftinv added s: needs review Issue/PR is awaiting reviews and removed s: in progress Issue/PR is being worked on labels Aug 22, 2025
@shiftinv shiftinv merged commit df5824e into master Aug 24, 2025
29 checks passed
@shiftinv shiftinv deleted the feature/components-v2 branch August 24, 2025 10:43
@github-project-automation github-project-automation bot moved this from Todo to Done in disnake Aug 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s: needs review Issue/PR is awaiting reviews t: api support Support of Discord API features
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants