Nyxx commands
Nyxx commands is a framework for easily creating slash commands and text commands for Discord using the nyxx library.
Insipred by discord.py's commands extension.
Features
- Easy command creation
- Automatic compatibility with Discord slash commands
- Compatibility with the nyxx library
- Argument parsing
Quick start
Create a bot:
Bot bot = Bot(
'<token>',
GatewayIntents.allUnprivileged,
prefix: '!',
guild: Snowflake('<guild id>'), // Omit if you want commands to be registered globally
);
Create and register a simple command:
Command command = Command(
'hi', // Command name
'A simple command', // Command description
(Context context, String name) async { // Command syntax and callback
await context.respond(MessageBuilder.content('Hello, $name!'));
},
);
bot.registerChild(command);
Use a custom type converter:
Command command = Command(
'pet',
'A command with a type converter',
(Context context, bool hasCat /* User input will automatically be converted */) async {
if (hasCat) {
await context.respond(MessageBuilder.content('I have a cat.'));
} else {
await context.respond(MessageBuilder.content('I do not have any pets.'));
}
},
);
Use an optional argument:
Command command = Command(
'sayhi',
'A command with an optional argument',
(Context context, String name, [String? familyName /* This parameter is optional. Notice that optional parameters are *not* named parameters! */]) async {
await context.respond(MessageBuilder.content('My name is $name ${familyName ?? ""}'));
},
);
// Also notice how the name "familyName" was converted to "family-name" in the registered slash command,
// this is to ensure discord accepts the parameter name.
Use a command group:
Group group = Group(
'say',
'An example group',
children: [
Command(
'hi',
'Say hi',
(Context context) async {
await context.respond(MessageBuilder.content('Hi!'));
},
),
Command(
'goodbye',
'Say goodbye',
(Context context) async {
await context.respond(MessageBuilder.content('Goodbye :('));
},
)
],
);
// Register the group to the bot
bot.registerChild(group);
Libraries
- nyxx_commands
- A framework for easily creating slash commands and text commands for Discord using the nyxx library.