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 8
8
SectionBuilder ,
9
9
SeparatorBuilder ,
10
10
TextDisplayBuilder ,
11
- ThumbnailBuilder ,
12
11
} from 'discord.js' ;
13
12
import { applyId } from './common' ;
14
13
@@ -30,7 +29,10 @@ export function Container(props: ContainerProps): ContainerBuilder {
30
29
container . setSpoiler ( props . spoiler ) ;
31
30
}
32
31
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
+
34
36
for ( const child of props . children . flat ( ) ) {
35
37
if ( child instanceof TextDisplayBuilder ) {
36
38
container . addTextDisplayComponents ( child ) ;
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ export function MediaGallery(props: MediaGalleryProps) {
12
12
applyId ( props , gallery ) ;
13
13
14
14
if ( props . children != null ) {
15
+ if ( ! Array . isArray ( props . children ) ) props . children = [ props . children ] ;
15
16
gallery . addItems ( props . children . flat ( ) ) ;
16
17
}
17
18
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ export function Section(props: SectionProps): SectionBuilder {
17
17
applyId ( props , section ) ;
18
18
19
19
if ( props . children != null ) {
20
+ if ( ! Array . isArray ( props . children ) ) props . children = [ props . children ] ;
20
21
for ( const accessory of props . children . flat ( ) ) {
21
22
if ( accessory instanceof ThumbnailBuilder ) {
22
23
section . setThumbnailAccessory ( accessory ) ;
Original file line number Diff line number Diff line change 1
1
import { TextDisplayBuilder , TextDisplayComponentData } from 'discord.js' ;
2
2
3
+ export type StringEncodable = string | number | boolean ;
4
+
3
5
export interface TextDisplayProps
4
6
extends Omit < TextDisplayComponentData , 'type' | 'content' > {
5
- children ?: string | string [ ] ;
7
+ children ?: StringEncodable | StringEncodable [ ] ;
6
8
content ?: string ;
7
9
}
8
10
@@ -13,7 +15,11 @@ export function TextDisplay(props: TextDisplayProps) {
13
15
if ( Array . isArray ( props . children ) ) {
14
16
textDisplay . setContent ( props . children . join ( ' ' ) ) ;
15
17
} else {
16
- textDisplay . setContent ( props . children ) ;
18
+ textDisplay . setContent (
19
+ typeof props . children === 'string'
20
+ ? props . children
21
+ : String ( props . children ) ,
22
+ ) ;
17
23
}
18
24
}
19
25
You can’t perform that action at this time.
0 commit comments