Options
Modules
  • Command
  • Localization
  • Logger
All
  • Public
  • Public/Protected
  • All
Menu

Class CommandContext<T>

Represents the context in which a Command is called

Type parameters

  • T: Client = Client

Hierarchy

  • CommandContext

Index

Constructors

Properties

Methods

Constructors

constructor

Properties

args

The parsed arguments that your Command received when called

author

author: User

The user that triggered the Command

client

client: T

The Client instance your Command is registered with

command

command: Command<T>

The command this context is for

message

message: Message

The Discord.js Message that triggered the Command

Methods

channel

  • channel<U>(): U
  • Utility function to get the channel the context message was sent in while allowing the passing of a channel type parameter to clean up channel typecasting (which can be a bother and often looks bad).

    Consider the following:

    const authorPerms: Readonly<Permissions> = (ctx.message.channel as TextChannel)
        .permissionsFor?.(ctx.message.author) ?? new Permissions();
    

    compared to:

    const authorPerms: Readonly<Permissions> = ctx
        .channel<TextChannel>()
        .permissionsFor?.(ctx.message.author) ?? new Permissions();
    

    Doesn't the second implementation look much cleaner? I sure think so! What? Function call overhead? Perf? What are those??

    Type parameters

    • U: DMChannel | TextChannel | NewsChannel

    Returns U

Generated using TypeDoc