CommandsPlugin class Null safety

The base plugin used to interact with nyxx_commands.

Since nyxx 3.0.0, classes can extend BasePlugin and be registered as plugins to an existing nyxx client by calling INyxx.registerPlugin. nyxx_commands uses that interface, which avoids the need for a seperate wrapper class.

Commands can be added to nyxx_commands with the addCommand method. Once you've added the CommandsPlugin to your nyxx client, these commands will automatically become available once the client is ready.

The CommandsPlugin will automatically subscribe to all the event streams it needs, as well as create its own instance of IInteractions for using slash commands. If you want to access this instance for your own use, it is available through the interactions getter.

For example, here is how you would create and register CommandsPlugin:

INyxxWebsocket client = NyxxFactory.createNyxxWebsocket(...);

CommandsPlugin commands = CommandsPlugin(
  prefix: (_) => '!',
);

client.registerPlugin(commands);
client.connect();

CommandsPlugin is also where Converters are managed and stored. New developers need not think about this as nyxx_commands comes with a set of default converters, but interested developers can take a look at addConverter and the Converter class.

You might also be interested in:

  • ChatCommand, for creating commands that can be executed through Slash Commands or text messages;
  • addCommand, for adding commands to your bot;
  • check, for adding checks to your bot;
  • MessageCommand and UserCommand, for creating Message and User Commands respectively.
Inheritance
Implemented types

Constructors

CommandsPlugin({required String prefix(IMessage), Snowflake? guild, CommandsOptions options = const CommandsOptions()})
Create a new CommandsPlugin.

Properties

checks List<AbstractCheck>
The checks that should be applied to this entity.
final
children Iterable<ICommandRegisterable<IContext>>
A list of all the children of this group
read-only, override
client INyxx?
The client this CommandsPlugin instance is attached to.
read / write
guild Snowflake?
The guild to register commands to.
read / write
hashCode int
The hash code for this object.
read-only, inherited
interactions IInteractions
The IInteractions instance used by this CommandsPlugin.
late, final
onCommandError Stream<CommandsException>
A stream of CommandsExceptions that occur during a command's execution.
late, final
onPostCall Stream<IContext>
A stream that emits contexts after the command callback is executed.
late, final
onPreCall Stream<IContext>
A stream that emits contexts before the command callback is executed.
late, final
options CommandsOptions
The options to use for this entity.
final
prefix String Function(IMessage)
A function called to determine the prefix for a specific message.
final
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

addCommand(ICommandRegisterable<IContext> command) → void
Add a command to this group.
override
addConverter<T>(Converter<T> converter) → void
Adds a converter to this CommandsPlugin.
check(AbstractCheck check) → void
Add a check to this entity.
override
getCommand(StringView view) ChatCommand?
Attempt to get a command from a string.
override
getConverter(Type type, {bool logWarn = true}) Converter?
Gets a Converter for a specific type.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
onBotStart(INyxx nyxx, Logger logger) FutureOr<void>
inherited
onBotStop(INyxx nyxx, Logger logger) Future<void>
override
onRegister(INyxx nyxx, Logger logger) → void
override
toString() String
A string representation of this object.
override
walkCommands() Iterable<ICommand<IContext>>
Returns an iterable that recursively iterates over all the ICommands in this group.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited