-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from nyxx-discord/main
Update dev to main
- Loading branch information
Showing
66 changed files
with
5,177 additions
and
4,132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ build/ | |
doc/ | ||
.vscode/ | ||
.idea/ | ||
pubspec_overrides.yaml |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,59 @@ | ||
# Nyxx commands | ||
# nyxx_commands | ||
|
||
Nyxx commands is a framework for easily creating slash commands and text commands for Discord using the [nyxx](https://pub.dev/packages/nyxx) library. | ||
nyxx_commands is a framework for easily creating slash commands and text commands for Discord using the [nyxx](https://pub.dev/packages/nyxx) library. | ||
|
||
Insipred by [discord.py](https://discordpy.readthedocs.io/en/stable/)'s [commands](https://discordpy.readthedocs.io/en/stable/ext/commands/index.html) extension. | ||
Inspired by [discord.py](https://discordpy.readthedocs.io/en/stable/)'s [commands](https://discordpy.readthedocs.io/en/stable/ext/commands/index.html) extension. | ||
|
||
Need help with nyxx_commands? Join our [Discord server](https://discord.gg/nyxx) and ask in the `#nyxx_commands` channel. | ||
|
||
## Features | ||
- Easy command creation | ||
- Automatic compatibility with Discord slash commands | ||
- Compatibility with the [nyxx](https://pub.dev/packages/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](https://api.dart.dev/dart-mirrors/dart-mirrors-library.html#status-unstable). | ||
|
||
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`](https://pub.dev/documentation/nyxx_commands/latest/nyxx_commands/id.html) and give each function a unique id. | ||
|
||
|
||
For example, this chat command: | ||
```dart | ||
final ping = ChatCommand( | ||
'ping', | ||
'Ping the bot', | ||
(IChatContext context) => context.respond(MessageBuilder.content('Pong!')), | ||
); | ||
``` | ||
must have its callback wrapped with `id` like so: | ||
```dart | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.