@@ -83,7 +83,12 @@ In the case of a command or subcommand, it is necessary to define a handler that
8383final commandBuilder = CommandBuilder()
8484 .setName('foo')
8585 .setDescription('This is a command description')
86- .setHandler((ctx) => ctx.interaction.reply('Hello, world!'));
86+ .setHandler((ctx) {
87+ final builder = MessageComponentBuilder()
88+ ..text('Hello from World');
89+
90+ ctx.interaction.reply(builder);
91+ });
8792```
8893
8994### Context
@@ -270,13 +275,24 @@ using the `.addSubCommand` method.
270275final commandBuilder = CommandBuilder()
271276 .setName('foo')
272277 .setDescription('This is a command description')
273- .setHandler((ctx) => ctx.interaction.reply('Hello, world!')); // [!code --]
274- // [!code ++:6]
278+ // [!code --:6]
279+ .setHandler((ctx) async {
280+ final builder = MessageComponentBuilder()
281+ ..text('Hello from World');
282+
283+ await ctx.interaction.reply(builder);
284+ });
285+ // [!code ++:11]
275286 .addSubCommand((command) {
276287 command
277288 .setName('bar')
278289 .setDescription('This is a subcommand description')
279- .setHandler((ctx) => ctx.interaction.reply('Hello, world!'));
290+ .setHandler((ctx) async {
291+ final builder = MessageComponentBuilder()
292+ ..text('Hello from World');
293+
294+ await ctx.interaction.reply(builder);
295+ });
280296 });
281297```
282298
@@ -297,8 +313,14 @@ When you define a group, you must add one or more subcommands to it.
297313final commandBuilder = CommandBuilder()
298314 .setName('foo')
299315 .setDescription('This is a command description')
300- .setHandler((ctx) => ctx.interaction.reply('Hello, world!')); // [!code --]
301- // [!code ++:11]
316+ // [!code --:6]
317+ .setHandler((ctx) async {
318+ final builder = MessageComponentBuilder()
319+ ..text('Hello from World');
320+
321+ await ctx.interaction.reply(builder);
322+ });
323+ // [!code ++:15]
302324 .createGroup((group) {
303325 group
304326 .setName('group')
@@ -307,7 +329,12 @@ final commandBuilder = CommandBuilder()
307329 command
308330 .setName('bar')
309331 .setDescription('This is a subcommand description')
310- .setHandler((ctx) => ctx.interaction.reply('Hello, world!'));
332+ .setHandler((ctx) async {
333+ final builder = MessageComponentBuilder()
334+ ..text('Hello from World');
335+
336+ await ctx.interaction.reply(builder);
337+ });
311338 });
312339 });
313340```
@@ -320,15 +347,20 @@ Once you have defined your order, you need to declare it in your client for it t
320347
321348``` dart
322349final client = ClientBuilder()
323- .setCache((e) => MemoryProvider() )
350+ .setCache(MemoryProvider.new )
324351 .build();
325352
326- // [!code highlight:6 ]
353+ // [!code ++:10 ]
327354client.commands.declare((command) {
328355 command
329356 ..setName('foo')
330357 ..setDescription('This is a command description')
331- ..setHandler((ctx) => ctx.interaction.reply('Hello, world!'));
358+ ..setHandler((ctx) async {
359+ final builder = MessageComponentBuilder()
360+ ..text('Hello from World');
361+
362+ await ctx.interaction.reply(builder);
363+ });
332364});
333365
334366await client.init();
@@ -372,7 +404,12 @@ final commandBuilder = CommandBuilder()
372404 'fr': 'Ceci est une commande de test',
373405 'en': 'This is a test command'
374406 }))
375- .setHandler((ctx) => ctx.interaction.reply('Hello, world!'));
407+ .setHandler((ctx) {
408+ final builder = MessageComponentBuilder()
409+ ..text('Hello from World');
410+
411+ ctx.interaction.reply(builder);
412+ });
376413```
377414
378415``` dart
@@ -382,7 +419,12 @@ final translation = Translation.file(file: file, key: 'test');
382419final commandBuilder = CommandBuilder()
383420 .setName('foo', translation: translation)
384421 .setDescription('This is a test command', translation: translation)
385- .setHandler((ctx) => ctx.interaction.reply('Hello, world!'));
422+ .setHandler((ctx) async {
423+ final builder = MessageComponentBuilder()
424+ ..text('Hello from World');
425+
426+ await ctx.interaction.reply(builder);
427+ });
386428```
387429
388430``` yaml
@@ -422,7 +464,12 @@ final commandBuilder = CommandBuilder()
422464 ' fr ' : ' Ceci est une sous-commande de test' ,
423465 ' en ' : ' This is a subcommand'
424466 }))
425- .setHandler((ctx) => ctx.interaction.reply('Hello, world!'));
467+ .setHandler((ctx) async {
468+ final builder = MessageComponentBuilder()
469+ ..text('Hello from World');
470+
471+ await ctx.interaction.reply(builder);
472+ });
426473 });
427474```
428475
@@ -438,7 +485,12 @@ final commandBuilder = CommandBuilder()
438485 command
439486 .setName('sub1', translation: subTranslation)
440487 .setDescription('This is a subcommand description', translation: subTranslation)
441- .setHandler((ctx) => ctx.interaction.reply('Hello, world!'));
488+ .setHandler((ctx) async {
489+ final builder = MessageComponentBuilder()
490+ ..text('Hello from World');
491+
492+ await ctx.interaction.reply(builder);
493+ });
442494 });
443495```
444496
@@ -499,7 +551,12 @@ final commandBuilder = CommandBuilder()
499551 ' fr ' : ' Ceci est une sous-commande de test' ,
500552 ' en ' : ' This is a subcommand'
501553 }))
502- .setHandler((ctx) => ctx.interaction.reply('Hello, world!'));
554+ .setHandler((ctx) async {
555+ final builder = MessageComponentBuilder()
556+ ..text('Hello from World');
557+
558+ await ctx.interaction.reply(builder);
559+ });
503560 });
504561 });
505562```
@@ -522,7 +579,12 @@ final commandBuilder = CommandBuilder()
522579 command
523580 .setName('sub1', translation: subTranslation)
524581 .setDescription('This is a subcommand description', translation: subTranslation)
525- .setHandler((ctx) => ctx.interaction.reply('Hello, world!'));
582+ .setHandler((ctx) async {
583+ final builder = MessageComponentBuilder()
584+ ..text('Hello from World');
585+
586+ await ctx.interaction.reply(builder);
587+ });
526588 })
527589 );
528590```
@@ -969,8 +1031,11 @@ In this example, we will use the command definition approach to define our comma
9691031
9701032` ` ` dart
9711033final class MyCommand implements CommandDeclaration {
972- FutureOr<void> handle(CommandContext ctx, {required int value}) {
973- ctx.interaction.reply('Selected value: $value');
1034+ FutureOr<void> handle(CommandContext ctx, {required int value}) async {
1035+ final builder = MessageComponentBuilder()
1036+ ..text('Selected value: $value');
1037+
1038+ await ctx.interaction.reply(builder);
9741039 }
9751040
9761041 @override
@@ -1008,8 +1073,11 @@ In this example, we will use the command definition approach to define our comma
10081073
10091074` ` ` dart
10101075final class MyCommand implements CommandDefinition {
1011- FutureOr<void> addRole(CommandContext ctx, {required Role role}) {
1012- ctx.interaction.reply('Role $role has been selected');
1076+ FutureOr<void> addRole(CommandContext ctx, {required Role role}) async {
1077+ final builder = MessageComponentBuilder()
1078+ ..text('Role $role has been selected');
1079+
1080+ await ctx.interaction.reply(builder);
10131081 }
10141082
10151083 @override
@@ -1070,13 +1138,15 @@ To register a command, you need to call the `register` method on your client and
10701138:::code-group labels=[Registering command]
10711139
10721140` ` ` dart
1073- final client = ClientBuilder()
1074- .build();
1141+ Future<void> main() async {
1142+ final client = ClientBuilder()
1143+ .build();
10751144
1076- // [!code ++]
1077- client.register(MyCommand.new) // 👈 Put your command
1145+ // [!code ++]
1146+ client.register(MyCommand.new) // 👈 Put your command
10781147
1079- await client.init();
1148+ await client.init();
1149+ }
10801150` ` `
10811151
10821152:: :
0 commit comments