@clytage/command-context
TypeScript icon, indicating that this package has built-in type declarations

4.3.0 • Public • Published
Clytage Logo

@clytage/command-context

Wrapping all sapphire commands (interaction, message) in one context

GitHub npm Discord

Installation

npm install @sapphire/framework@next discord.js @sapphire/utilities @clytage/command-context

Example ContextCommand

import { ApplicationCommandRegistry, Command, RegisterBehavior } from "@sapphire/framework";
import { CommandContext } from "@clytage/command-context";
import { ApplyOptions } from "@sapphire/decorators";

@ApplyOptions<Command.Options>({
    name: "ping",
    description: "A ping command.",
    chatInputCommand: {
        register: true
    }
})

export class PingCommand extends ContextCommand {
    public contextRun(ctx: CommandContext): unknown {
        return ctx.send({
            content: "PONG!"
        });
    }

    public override registerApplicationCommands(registry: ApplicationCommandRegistry): void {
        registry.registerChatInputCommand({
            name: this.name,
            description: this.description
        }, {
            behaviorWhenNotIdentical: RegisterBehavior.Overwrite,
            registerCommandIfMissing: true
        });
    }
}

Example ContextPrecondition

import { CommandContext, ContextPrecondition } from "@clytage/command-context";
import type { Precondition } from "@sapphire/framework";
import { ApplyOptions } from "@sapphire/decorators";

@ApplyOptions<Precondition.Options>({
    name: "isAdministrator"
})

export class isAdministrator extends ContextPrecondition {
    public contextRun(context: CommandContext) {
        return context.member!.id === context.guild ? .ownerId ? this.ok() : this.error({
            message: "You are not the administrator."
        });
    }
}

declare module "@sapphire/framework" {
    interface Preconditions {
        isAdministrator: never;
    }
}

Readme

Keywords

none

Package Sidebar

Install

npm i @clytage/command-context

Weekly Downloads

24

Version

4.3.0

License

AGPL-3.0

Unpacked Size

92.3 kB

Total Files

40

Last publish

Collaborators

  • cligodartfott
  • mozartrafi