Conversation
Major overhaul of the component system: - Introduce strongly-typed JSON models for each component type (e.g., Button, ActionRow, StringMenu, etc.) - Add custom JsonConverter for dynamic deserialization based on component type - Update all component classes to use their specific JSON models and implement IJsonModel<T> - Add support for new component types: Checkbox, CheckboxGroup, and RadioGroup, with their option models - Remove obsolete generic option classes and replace with specific ones - Make key properties non-nullable where required by Discord API - Update helper methods and interfaces for type safety and consistency - Minor fixes: property naming, payload processing, and add a sample slash command - Add new files for new component and option types These changes modernize and strongly type the component system, improving robustness, extensibility, and maintainability.
|
The documentation preview is available at https://preview.netcord.dev/258. |
There was a problem hiding this comment.
Pull request overview
This pull request adds support for three new Discord component types (RadioGroup, CheckboxGroup, and Checkbox) and significantly refactors the component deserialization architecture for improved type safety. The refactor replaces the previous approach of using a single JsonComponent class with many nullable properties with a polymorphic class hierarchy where each component type has its own strongly-typed class.
Changes:
- Added RadioGroup, CheckboxGroup, and Checkbox component support with corresponding JSON models and component classes
- Rewrote component deserialization to use a custom JsonConverter that deserializes to specific typed classes (JsonButtonComponent, JsonStringMenuComponent, etc.) based on the component type discriminator
- Updated all existing component classes to use specific typed JsonComponent subclasses, removing reliance on nullable properties and improving type safety throughout the component system
Reviewed changes
Copilot reviewed 41 out of 41 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| NetCord/Components/ComponentType.cs | Added enum values for RadioGroup (21), CheckboxGroup (22), and Checkbox (23) component types |
| NetCord/Components/RadioGroup.cs | New component class for radio group inputs (marked internal) |
| NetCord/Components/CheckboxGroup.cs | New component class for checkbox group inputs with selected values array |
| NetCord/Components/Checkbox.cs | New component class for single checkbox input with boolean selected state |
| NetCord/JsonModels/JsonComponent.cs | Major refactor: added JsonComponentConverter and specific typed classes for each component type, replacing nullable property pattern |
| NetCord/JsonModels/JsonRadioGroupOption.cs | JSON model for radio group option properties |
| NetCord/JsonModels/JsonCheckboxGroupOption.cs | JSON model for checkbox group option properties |
| NetCord/JsonModels/JsonStringMenuSelectOption.cs | Renamed from JsonMenuSelectOption for clarity |
| NetCord/Rest/ComponentProperties/RadioGroupProperties.cs | Properties class for creating radio group components in modals |
| NetCord/Rest/ComponentProperties/CheckboxGroupProperties.cs | Properties class for creating checkbox group components in modals |
| NetCord/Rest/ComponentProperties/CheckboxProperties.cs | Properties class for creating checkbox components in modals |
| NetCord/Rest/ComponentProperties/StringMenuProperties.cs | Refactored IStringMenuProperties to extend IInteractiveComponentProperties |
| NetCord/Components/*.cs (multiple files) | Updated to use specific typed JsonComponent subclasses and implement IJsonModel with specific types |
| NetCord/Components/EntityMenuHelper.cs | Changed parameter types from string[] to IEnumerable for type safety |
| NetCord/Components/IComponent.cs | Updated all CreateFromJson methods to accept and cast to specific typed components |
| NetCord/EntityMenuInteraction.cs | Updated to work with typed ulong arrays instead of string arrays for selected values |
| NetCord/Serialization.cs | Added JSON serialization context entries for all new component types |
| NetCord/Gateway/GatewayClient.cs | Added debug Console.WriteLine (should be removed) and refactored payload processing |
| Tests/NetCord.Test.Hosting/Program.cs | Added test command demonstrating usage of new component types |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 41 out of 41 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Changed CustomId to string? in JsonButtonComponent to allow null values. Updated Button.CustomId to use the null-forgiving operator to reflect this change and ensure non-null usage where required.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 41 out of 41 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Changed the getValues delegate parameter in EntityMenu.GetSelectedValues from ulong[] to IEnumerable<ulong> for greater flexibility, allowing support for any enumerable collection of ulong values. This improves compatibility and extensibility of the method.
Introduce JsonComponentInternal struct for unknown types, updating deserialization logic to only retain Type and Id. Add JsonComponentInternal to serialization metadata for proper source generation support.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 41 out of 41 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 39 out of 39 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Removed use of null-forgiving operators when accessing jsonModel.Accessory and jsonModel.Components, passing them directly instead. Also simplified the Select call for Components by using a method group.
Refactored component and JSON model classes to match API structure: - Added AttachmentId to ComponentMedia/JsonComponentMedia. - Made Spoiler non-nullable and added Name/Size to FileDisplay/JsonFileDisplayComponent. - Made Divider and Spacing non-nullable in ComponentSeparator/JsonComponentSeparatorComponent. These changes improve type safety and expose additional metadata.
Removed the null-forgiving operator (!) from property initializations in ActionRow, ComponentContainer, and FileUpload. This reflects increased confidence that these properties are non-null and improves code clarity by not suppressing nullability warnings unnecessarily.
Replaces ComponentSectionThumbnail with Thumbnail and updates all references to use the new class and JSON model. Makes Spoiler, Name, and Size properties nullable in FileDisplay and its JSON model. Updates ComponentSeparator and Menu models to use nullable properties with appropriate defaults. Improves handling of optional fields and clarifies component type separation, especially for thumbnails. Also reorganizes JSON model class order for clarity.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 42 out of 42 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Renamed Selected/SelectedValues to Checked/CheckedValues for clarity. FileDisplay Name and Size now have default (non-null) values. Added MinValues, MaxValues, and Required to CheckboxGroupProperties. Updated Program.cs to demonstrate new checkbox group features.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 42 out of 42 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
No description provided.