Clone the repository and run the following command:
$ npm install
Install Sapphire CLI:
$ npm install -g @sapphire/cli
Create command/listener/precondition by Sapphire CLI:
$ sapphire generate command <command_name>
$ sapphire generate listener <listener_name>
$ sapphire generate precondition <precondition_name>
- The CLI will create a file in the corresponding directory with the type of the command/listener/precondition.
- Open the generated file and click on the last character.
Ctrl + Space
to show the snippets.Enter
to use the snippet.
You can change the command/listener/precondition name in the command to <directoryName>/<command/listener/precondition_name>
Command structure code example:
import { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
import { ApplyOptions } from '@sapphire/decorators';
import { ApplicationCommandRegistry, Command, CommandOptions, RegisterBehavior } from '@sapphire/framework';
import type { CommandInteraction, ContextMenuInteraction } from 'discord.js';
@ApplyOptions<CommandOptions>({
name: 'name',
description: 'description',
preconditions: ['Defer'],
requiredClientPermissions: [BigInt(277025770560)],
requiredUserPermissions: ['USE_EXTERNAL_EMOJIS']
})
export default class NameCommand extends Command {
public override registerApplicationCommands(registry: ApplicationCommandRegistry) {
// Register the slash command/context menu command
}
public async chatInputRun(interaction: CommandInteraction) {
// Handle chat input command
}
public async contextMenuRun(interaction: ContextMenuInteraction) {
// Handle context menu command
}
}
Listener structure code example:
import { Listener } from '@sapphire/framework';
import type {} from 'discord.js';
export default class NameListener extends Listener {
public constructor(context: Listener.Context, options: Listener.Options) {
super(context, {
...options,
name: 'Name'
});
}
public async run() {}
}
Precondition structure code example:
import { PieceContext, Precondition } from '@sapphire/framework';
import type { CommandInteraction } from 'discord.js';
export default class NamePrecondition extends Precondition {
public constructor(context: PieceContext, options: Precondition.Options) {
super(context, {
...options,
name: 'Name'
});
}
public async chatInputRun(interaction: CommandInteraction) {
// Handle chat input command
}
public async contextMenuRun(interaction: CommandInteraction) {
// Handle context menu command
}
}
declare module '@sapphire/framework' {
interface Preconditions {
Name: never;
}
}