CommandsPlugin class

The base plugin used to interact with nyxx_commands.

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. It will also bulk override all globally registered slash commands and guild commands in the guilds where commands with GuildChecks are registered.

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

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

final client = await Nyxx.connectGateway(
  token,
  intents,
  options: GatewayClientOptions(plugins: [commands]),
);

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 FutureOr<Pattern> prefix(MessageCreateEvent)?, 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<CommandRegisterable<CommandContext>>
A list of all the children of this group
no setteroverride
clientType RuntimeType<NyxxGateway>
The type of client this plugin requires.
no setterinherited
contextManager ContextManager
The ContextManager attached to this CommandsPlugin.
latefinal
eventManager EventManager
The EventManager attached to this CommandsPlugin.
latefinal
guild Snowflake?
The guild to register commands to.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
logger Logger
A logger that can be used to log messages from this plugin.
no setterinherited
name String
The name of this plugin.
no setteroverride
onCommandError Stream<CommandsException>
A stream of CommandsExceptions that occur during a command's execution.
latefinal
onPostCall Stream<CommandContext>
A stream that emits contexts after the command callback is executed.
latefinal
onPreCall Stream<CommandContext>
A stream that emits contexts before the command callback is executed.
latefinal
options CommandsOptions
The options to use for this entity.
final
prefix → (FutureOr<Pattern> Function(MessageCreateEvent)?)
A function called to determine the prefix for a specific message.
final
registeredCommands List<ApplicationCommand>
A list of commands registered by this CommandsPlugin to the Discord API.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addCommand(covariant CommandRegisterable<CommandContext> command) → void
Add a command to this group.
override
addConverter<T>(Converter<T> converter) → void
Adds a converter to this CommandsPlugin.
afterClose() FutureOr<void>
Called after each client this plugin is added to closes.
inherited
afterConnect(NyxxGateway client) Future<void>
Called after each client this plugin is added to connects.
override
beforeClose(NyxxGateway client) → void
Called before each client this plugin is added to closes.
override
beforeConnect(ApiOptions apiOptions, ClientOptions clientOptions) FutureOr<void>
Called before each client this plugin is added to connects.
inherited
check(AbstractCheck check) → void
Add a check to this entity.
override
createState() FutureOr<NyxxPluginState<NyxxGateway, NyxxPlugin<NyxxGateway>>>
Called to create the state for this plugin.
inherited
doClose(NyxxGateway client, Future<void> close()) Future<void>
Perform the close operation.
inherited
doConnect(ApiOptions apiOptions, ClientOptions clientOptions, Future<NyxxGateway> connect()) Future<NyxxGateway>
Perform the connection operation.
inherited
getCommand(StringView view) ChatCommand?
Attempt to get a command from a string.
override
getConverter<T>(RuntimeType<T> type, {bool logWarn = true}) Converter<T>?
Gets a Converter for a specific type.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
override
walkCommands() Iterable<Command<CommandContext>>
Returns an iterable that recursively iterates over all the Commands in this group.
override

Operators

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