nyxx_commands 6.0.2 copy "nyxx_commands: ^6.0.2" to clipboard
nyxx_commands: ^6.0.2 copied to clipboard

A framework for easily creating slash commands and text commands for Discord using the nyxx library.

nyxx_commands #

nyxx_commands is a framework for easily creating slash commands and text commands for Discord using the nyxx library.

Inspired by discord.py's commands extension.

Need help with nyxx_commands? Join our Discord server and ask in the #nyxx_commands channel.

Features #

  • Easy command creation
  • Automatic compatibility with Discord slash commands
  • Compatibility with the nyxx library
  • Argument parsing

Compiling nyxx_commands #

If you compile a bot using nyxx_commands with dart compile exe, you might get an error you hadn't seen during development:

Error: Function data was not correctly loaded. Did you compile the wrong file?
Stack trace:
#0      loadFunctionData (package:nyxx_commands/src/mirror_utils/compiled.dart:10)
#1      ChatCommand._loadArguments (package:nyxx_commands/src/commands/chat_command.dart:354)
...

This is because nyxx_commands uses dart:mirrors to load the arguments for your commands. During development this is fine but this functionality breaks when compiled because dart:mirrors cannot be used in compiled Dart programs.

To mitigate this, nyxx_commands provides a script that compiles your code for you and loads this information for nyxx_commands to use. To use it, you must first wrap all your command callbacks in id and give each function a unique id.

For example, this chat command:

final ping = ChatCommand(
  'ping',
  'Ping the bot',
  (IChatContext context) => context.respond(MessageBuilder.content('Pong!')),
);

must have its callback wrapped with id like so:

final ping = ChatCommand(
  'ping',
  'Ping the bot',
  id('ping', (IChatContext context) => context.respond(MessageBuilder.content('Pong!'))),
);

If you forget to add the id to a function, you'll get an error similar to this one:

Error: Command Exception: Couldn't load function data for function Closure: (IChatContext) => Null
Stack trace:
#0      loadFunctionData (package:nyxx_commands/src/mirror_utils/compiled.dart:18)
#1      ChatCommand._loadArguments (package:nyxx_commands/src/commands/chat_command.dart:354)
...

Once you've added id to all your commands, use the nyxx_commands:compile script to compile your program. See dart run nyxx_commands:compile --help for a list of options.

If you use the --no-compile flag, make sure that you run/compile the generated file and not your own main file.

8
likes
120
pub points
78%
popularity

Publisher

verified publisherl7ssha.xyz

A framework for easily creating slash commands and text commands for Discord using the nyxx library.

Homepage
Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

Apache-2.0 (LICENSE)

Dependencies

analyzer, args, dart_style, fuzzywuzzy, logging, nyxx, path, runtime_type

More

Packages that depend on nyxx_commands