Skip to content

Conversation

@Droid00000
Copy link
Collaborator

@Droid00000 Droid00000 commented Feb 24, 2025

Summary

This is my attempt at adding support for the new components that Discord plans to release in the distant future. This introduces the ability to have components besides action rows as top-level components, as well as the ability to nest action rows within other top-level components. Additionally, this PR now includes the Label component that will be coming to modals along with the ability to have TextDisplay components in modals. Some potential points to discuss:

  • The example admittedly isn't the best. I'm open to doing something different than what I've current added.
  • has_components admittedly isn't the best name for setting the IS_COMPONENTS_V2 (1 << 15) flag.

Added

  • Builders for new components:
    Webhooks::View::TextDisplayBuilder
    Webhooks::View::SeperatorBuilder
    Webhooks::View::FileBuilder
    Webhooks::View::MediaGalleryBuilder
    Webhooks::View::SectionBuilder
    Webhooks::View::ContainerBuilder
    Webhooks::Modal::LabelBuilder

  • Top-level methods for new components:
    Webhooks::View#text_display
    Webhooks::View#seperator
    Webhooks::View#file
    Webhooks::View#media_gallery
    Webhooks::View#section
    Webhooks::View#container
    Webhooks::Modal#text_display
    Webhooks::Modal#label

  • Data classes for serializing incoming components:
    Components::TextDisplay
    Components::Seperator
    Components::File
    Components::MediaGallery
    Components::Section
    Components::Container
    Components::Label
    Components::FileUpload

has_components KWARG for interaction methods which sets the IS_COMPONENTS_V2 (1 << 15) flag.
Channel#send_message!(**arguments) Same as send_message but with KWARGS and yielded builders.

Changed

There are a couple of internal changes made to Webhooks::View in order to make the new components possible. (Don't worry, full backwards compatibility has been maintained.)

Removal of @rows. Since action rows are no longer the only top-level components, it didn't make sense to have two separate instance variables since it would end up requiring some needless concatenation. E.g.

@rows.map(&:to_h).concact(@components.map(&:to_h))

In its place, I've replaced it with @components as a way to store all top-level components. This required the removal of the attr_reader :rows as well. It was replaced with:

def rows
  @components.select { |component| component.is_a?(RowBuilder) }
end

Fixed

Previously, when passing in an emoji object to RowBuilder#button and SelectMenuBuilder#option, it would yield the following error:

Exception: #<NoMethodError: undefined method `to_h' for an instance of Discordrb::Emoji>

As stated in the error, this is because #to_h wasn't defined anywhere for the emoji object. I've went ahead and defined this method.

@Droid00000 Droid00000 force-pushed the message-components branch 6 times, most recently from 7073e2a to 61d1711 Compare August 14, 2025 04:15
@Droid00000 Droid00000 force-pushed the message-components branch 4 times, most recently from dc2608a to 08a9831 Compare August 16, 2025 22:08
@Droid00000 Droid00000 force-pushed the message-components branch 14 times, most recently from 81a6ddf to 12c68a3 Compare August 28, 2025 03:10
@Droid00000 Droid00000 force-pushed the message-components branch 4 times, most recently from 3296833 to 37494e6 Compare September 17, 2025 22:33
@Droid00000 Droid00000 force-pushed the message-components branch 2 times, most recently from 083512e to 23596dd Compare September 19, 2025 01:05
@Droid00000 Droid00000 force-pushed the message-components branch 2 times, most recently from dde4663 to 5b0f709 Compare October 3, 2025 21:39
@Droid00000 Droid00000 assigned Droid00000 and swarley and unassigned Droid00000 Oct 23, 2025
@Droid00000 Droid00000 added enhancement New feature or request interactions Deals with interactions or slash commands labels Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request interactions Deals with interactions or slash commands

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants