File tree Expand file tree Collapse file tree 5 files changed +40
-4
lines changed
apps/test-bot/src/app/commands/(general)
packages/commandkit/src/components/v2 Expand file tree Collapse file tree 5 files changed +40
-4
lines changed Original file line number Diff line number Diff line change 1+ import {
2+ ChatInputCommand ,
3+ CommandData ,
4+ Container ,
5+ TextDisplay ,
6+ } from 'commandkit' ;
7+ import { Colors , MessageFlags } from 'discord.js' ;
8+
9+ export const command : CommandData = {
10+ name : 'components-test' ,
11+ description : 'Test components v2 again' ,
12+ } ;
13+
14+ export const chatInput : ChatInputCommand = async ( ctx ) => {
15+ const container = (
16+ < Container accentColor = { Colors . Fuchsia } >
17+ < TextDisplay content = "# CommandKit Components v2 test" />
18+ </ Container >
19+ ) ;
20+
21+ await ctx . interaction . reply ( {
22+ components : [ container ] ,
23+
24+ flags : MessageFlags . IsComponentsV2 ,
25+ } ) ;
26+ } ;
Original file line number Diff line number Diff line change 88 SectionBuilder ,
99 SeparatorBuilder ,
1010 TextDisplayBuilder ,
11- ThumbnailBuilder ,
1211} from 'discord.js' ;
1312import { applyId } from './common' ;
1413
@@ -30,7 +29,10 @@ export function Container(props: ContainerProps): ContainerBuilder {
3029 container . setSpoiler ( props . spoiler ) ;
3130 }
3231
33- if ( props . children ?. length ) {
32+ if ( props . children != null ) {
33+ if ( ! Array . isArray ( props . children ) ) props . children = [ props . children ] ;
34+ if ( props . children . length === 0 ) return container ;
35+
3436 for ( const child of props . children . flat ( ) ) {
3537 if ( child instanceof TextDisplayBuilder ) {
3638 container . addTextDisplayComponents ( child ) ;
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ export function MediaGallery(props: MediaGalleryProps) {
1212 applyId ( props , gallery ) ;
1313
1414 if ( props . children != null ) {
15+ if ( ! Array . isArray ( props . children ) ) props . children = [ props . children ] ;
1516 gallery . addItems ( props . children . flat ( ) ) ;
1617 }
1718
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ export function Section(props: SectionProps): SectionBuilder {
1717 applyId ( props , section ) ;
1818
1919 if ( props . children != null ) {
20+ if ( ! Array . isArray ( props . children ) ) props . children = [ props . children ] ;
2021 for ( const accessory of props . children . flat ( ) ) {
2122 if ( accessory instanceof ThumbnailBuilder ) {
2223 section . setThumbnailAccessory ( accessory ) ;
Original file line number Diff line number Diff line change 11import { TextDisplayBuilder , TextDisplayComponentData } from 'discord.js' ;
22
3+ export type StringEncodable = string | number | boolean ;
4+
35export interface TextDisplayProps
46 extends Omit < TextDisplayComponentData , 'type' | 'content' > {
5- children ?: string | string [ ] ;
7+ children ?: StringEncodable | StringEncodable [ ] ;
68 content ?: string ;
79}
810
@@ -13,7 +15,11 @@ export function TextDisplay(props: TextDisplayProps) {
1315 if ( Array . isArray ( props . children ) ) {
1416 textDisplay . setContent ( props . children . join ( ' ' ) ) ;
1517 } else {
16- textDisplay . setContent ( props . children ) ;
18+ textDisplay . setContent (
19+ typeof props . children === 'string'
20+ ? props . children
21+ : String ( props . children ) ,
22+ ) ;
1723 }
1824 }
1925
You can’t perform that action at this time.
0 commit comments