Standalone Commands
Standalone commands are fully executable, top level commands that don't store any children. In Discord, they are triggered on Slash Commands.
Creation
Creation
Extend the AbstractStandaloneCommand class:
import { } from '@nyx-discord/djs';
class extends {}Implementation
Implement data that stores the command's data, and execute() that executes the command.
import { , type } from 'discord.js';
import { } from '@nyx-discord/djs';
class extends {
protected readonly = new ()
.('my-command')
.('My command')
.();
public async (: ) {
await .('Hello!');
}
}Guild deployment
By default, all commands will be deployed in the global scope. If you want to deploy them in a specific guild, you can do so by implementing the getGuilds() method.
import { } from '@nyx-discord/djs';
class extends {
public () {
return ['GUILD_ID', 'ANOTHER_GUILD_ID'];
}
}If you're ever overriding from another base command, you can return null to make it global again, this is the default implementation.
Execution Meta
The second argument of the execute method is a Metadata object, which is a Record that stores metadata about the command call.
Apart from the keys saved by the caller or the middleware, the dispatch meta contains:
- The execution ID, via the
TypedFields.Idfield. - The execution start date, via the
TypedFields.CreationDatefield. - The bot whose
Clientsent the interaction, via theTypedFields.Botfield.
To learn more about TypedFields, check the Metadata page.
Autocompletion
If your command has autocompletable options, you can implement the autocomplete() method.
import type { } from 'discord.js';
import { } from '@nyx-discord/djs';
class extends {
public async (: ) {
await .([
{ : 'First option', : 'first' },
{ : 'Second option', : 'second' },
]);
}
}Metadata
When extending nyx with plugins, you may want to specify extra data for them. You can do so with the Metadata object, saved on the command.
While commands internally save a Metadata, the return type of #getMeta() is a ReadonlyMetadata,
meaning that external objects can read the object, but not modify it.
import { } from '@nyx-discord/djs';
class extends {
protected override readonly = {
: 'someValue',
};
}
const = new ();
const = .();
const = ['someKey']; // 'someValue'For a more type-safe approach, you can use TypedFields. Check the Metadata page for more information.
