Class: KlasaClient

KlasaClient

The client for handling everything. See Getting Started for more information how to get started using this class.

new KlasaClient(config)

Constructs the klasa client
Parameters:
Name Type Description
config KlasaClientConfig The config to pass to the new client
Since:
  • 0.0.1
Source:
lib/Client.js#L77
Tutorials:

Extends

Properties


<static> defaultPermissionLevels :PermissionLevels

The default PermissionLevels
Type:
Since:
  • 0.2.1
Source:
lib/Client.js#L435

application :external:ClientApplication

The application info cached from the discord api
Type:
Since:
  • 0.0.1
Source:
lib/Client.js#L261

argResolver :ArgResolver

The argument resolver
Type:
Since:
  • 0.0.1
Source:
lib/Client.js#L125

clientBaseDir :string

The directory where the user files are at
Type:
  • string
Since:
  • 0.0.1
Source:
lib/Client.js#L105

commandMessageLifetime :number

The threshold for how old command messages can be before sweeping since the last edit in seconds
Type:
  • number
Since:
  • 0.0.1
Source:
lib/Client.js#L209

commandMessages :external:Collection

The cache of command messages and responses to be used for command editing
Type:
Since:
  • 0.0.1
Source:
lib/Client.js#L195

commandMessageSweep :number

The interval duration for which command messages should be sweept in seconds
Type:
  • number
Since:
  • 0.0.1
Source:
lib/Client.js#L216

commands :CommandStore

The cache where commands are stored
Type:
Since:
  • 0.0.1
Source:
lib/Client.js#L132

config :KlasaClientConfig

The config passed to the new Klasa.Client
Type:
  • KlasaClientConfig
Since:
  • 0.0.1
Source:
lib/Client.js#L86

console :KlasaConsole

The console for this instance of klasa. You can disable timestmaps, colors, and add writable streams as config options to configure this.
Type:
Since:
  • 0.4.0
Source:
lib/Client.js#L112

coreBaseDir :string

The directory to the node_modules folder where Klasa exists
Type:
  • string
Since:
  • 0.0.1
Source:
lib/Client.js#L98

events :EventStore

The cache where events are stored
Type:
Since:
  • 0.0.1
Source:
lib/Client.js#L174

extendables :ExtendableStore

The cache where extendables are stored
Type:
Since:
  • 0.0.1
Source:
lib/Client.js#L181

finalizers :FinalizerStore

The cache where finalizers are stored
Type:
Since:
  • 0.0.1
Source:
lib/Client.js#L146

inhibitors :InhibitorStore

The cache where inhibitors are stored
Type:
Since:
  • 0.0.1
Source:
lib/Client.js#L139

<readonly> invite

The invite link for the bot
Since:
  • 0.0.1
Source:
lib/Client.js#L282

languages :LanguageStore

The cache where languages are stored
Type:
Since:
  • 0.2.1
Source:
lib/Client.js#L160

methods :object

Additional methods to be used elsewhere in the bot
Type:
  • object
Properties:
Name Type Description
Collection class A discord.js collection
Embed class A discord.js Message Embed
MessageCollector class A discord.js MessageCollector
Webhook class A discord.js WebhookClient
escapeMarkdown function A discord.js escape markdown function
splitMessage function A discord.js split message function
CommandMessage class A command message
util Util A collection of static methods to be used thoughout the bot
Since:
  • 0.0.1
Source:
lib/Client.js#L238

monitors :MonitorStore

The cache where monitors are stored
Type:
Since:
  • 0.0.1
Source:
lib/Client.js#L153

<readonly> owner :external:User

The owner for this bot
Type:
Since:
  • 0.1.1
Source:
lib/Client.js#L377

permissionLevels :PermissionLevels

The permissions structure for this bot
Type:
Since:
  • 0.0.1
Source:
lib/Client.js#L202

pieceStores :external:Collection

A Store registry
Type:
Since:
  • 0.3.0
Source:
lib/Client.js#L188

providers :ProviderStore

The cache where providers are stored
Type:
Since:
  • 0.0.1
Source:
lib/Client.js#L167

ready :boolean

Whether the client is truely ready or not
Type:
  • boolean
Since:
  • 0.0.1
Source:
lib/Client.js#L223

settings :Object

The object where the gateways are stored settings
Type:
  • Object
Since:
  • 0.3.0
Source:
lib/Client.js#L254

Methods


<async> login(token)

Use this to login to Discord with your bot
Parameters:
Name Type Description
token string Your bot token
Since:
  • 0.0.1
Source:
lib/Client.js#L358
Returns:
Type
Promise.<string>

registerPiece(pieceName, store)

Registers a custom piece to the client
Parameters:
Name Type Description
pieceName string The name of the piece, if you want to register an arg resolver for this piece
store Store The store that pieces will be stored in.
Since:
  • 0.3.0
Source:
lib/Client.js#L330
Returns:
this client
Type
KlasaClient

registerStore(store)

Registers a custom store to the client
Parameters:
Name Type Description
store Store The store that pieces will be stored in.
Since:
  • 0.3.0
Source:
lib/Client.js#L307
Returns:
this client
Type
KlasaClient

sweepCommandMessages(lifetime)

Sweeps command messages based on the lifetime parameter
Parameters:
Name Type Description
lifetime number The threshold for how old command messages can be before sweeping since the last edit in seconds
Since:
  • 0.0.1
Source:
lib/Client.js#L409
Returns:
The amount of messages swept
Type
number

unregisterPiece(pieceName)

Unregisters a custom piece from the client
Parameters:
Name Type Description
pieceName string The name of the piece
Since:
  • 0.3.0
Source:
lib/Client.js#L347
Returns:
this client
Type
KlasaClient

unregisterStore(storeName)

Unregisters a custom store from the client
Parameters:
Name Type Description
storeName Store The store that pieces will be stored in.
Since:
  • 0.3.0
Source:
lib/Client.js#L318
Returns:
this client
Type
KlasaClient

Type Definitions


KlasaClientConfig

Type:
  • Object
Properties:
Name Type Argument Default Description
prefix string The default prefix the bot should respond to
clientOptions DiscordJSConfig <optional>
{} The options to pass to D.JS
permissionLevels PermissionLevels <optional>
KlasaClient.defaultPermissionLevels The permission levels to use with this bot
clientBaseDir string <optional>
path.dirname(require.main.filename) The directory where all piece folders can be found
commandMessageLifetime number <optional>
1800 The threshold for how old command messages can be before sweeping since the last edit in seconds
commandMessageSweep number <optional>
900 The interval duration for which command messages should be sweept in seconds
provider object <optional>
The provider to use in Klasa
console KlasaConsoleConfig <optional>
{} Config options to pass to the client console
consoleEvents KlasaConsoleEvents <optional>
{} Config options to pass to the client console
language string <optional>
'en-US' The default language Klasa should opt-in for the commands
promptTime number <optional>
30000 The amount of time in milliseconds prompts should last
ignoreBots boolean <optional>
true Whether or not this bot should ignore other bots
ignoreSelf boolean <optional>
true Whether or not this bot should ignore itself
cmdPrompt boolean <optional>
false Whether the bot should prompt missing parameters
cmdEditing boolean <optional>
false Whether the bot should update responses if the command is edited
cmdLogging boolean <optional>
false Whether the bot should log command usage
typing boolean <optional>
false Whether the bot should type while processing commands.
quotedStringSupport boolean <optional>
false Whether the bot should default to using quoted string support in arg parsing, or not (overridable per command)
readyMessage string | function <optional>
<nullable>
`Successfully initialized. Ready to serve ${this.guilds.size} guilds.` readyMessage to be passed thru Klasa's ready event
ownerID string <optional>
The discord user id for the user the bot should respect as the owner (gotten from Discord api if not provided)
Source:
lib/Client.js#L26

KlasaConsoleConfig

Type:
  • Object
Properties:
Name Type Argument Default Description
stdout WriteableStream <optional>
process.stdout Output stream
stderr WriteableStream <optional>
process.stderr Error stream
useColor boolean <optional>
false Whether the client console should use colors
colors Colors <optional>
Color formats to use
timestamps boolean | string <optional>
true Whether to use timestamps or not, or the moment format of the timestamp you want to use
Source:
lib/Client.js#L51

KlasaConsoleEvents

Type:
  • Object
Properties:
Name Type Argument Default Description
log boolean <optional>
true If the log event should be enabled by default
warn boolean <optional>
true If the warn event should be enabled by default
error boolean <optional>
true If the error event should be enabled by default
debug boolean <optional>
false If the debug event should be enabled by default
verbose boolean <optional>
false If the verbose event should be enabled by default
wtf boolean <optional>
true If the wtf event should be enabled by default
Source:
lib/Client.js#L61

Events


commandError

Emitted when a command has errored.
Parameters:
Name Type Description
message CommandMessageProxy The message that triggered the command
command Command The command run
params Array.<any> The resolved parameters of the command
error string | Object The command error
Since:
  • 0.3.0
Source:
lib/Client.js#L498

commandInhibited

Emitted when a command has been inhibited.
Parameters:
Name Type Argument Description
message external:Message The message that triggered the command
command Command The command triggered
response string <nullable>
The reason why it was inhibited if not silent
Since:
  • 0.3.0
Source:
lib/Client.js#L479

commandRun

Emitted when a command has been run.
Parameters:
Name Type Argument Description
message CommandMessageProxy The message that triggered the command
command Command The command run
params Array.<any> The resolved parameters of the command
response any <nullable>
Usually a response message, but whatever the command returned.
Since:
  • 0.3.0
Source:
lib/Client.js#L488

commandUnknown

Emitted when an unknown command is called.
Parameters:
Name Type Description
message external:Message The message that triggered the command
command string The command attempted to run
Since:
  • 0.4.0
Source:
lib/Client.js#L471

klasaReady

Emitted when klasa is fully ready and initialized.
Since:
  • 0.3.0
Source:
lib/Client.js#L443

log

A central logging event for klasa.
Parameters:
Name Type Argument Default Description
data string | Object The data to log
type string <optional>
'log' The type of log: 'log', 'debug', 'warn', or 'error'.
Since:
  • 0.3.0
Source:
lib/Client.js#L449

pieceDisabled

Emitted when a piece is disabled.
Parameters:
Name Type Description
piece Piece The piece that was disabled
Since:
  • 0.4.0
Source:
lib/Client.js#L546

pieceEnabled

Emitted when a piece is enabled.
Parameters:
Name Type Description
piece Piece The piece that was enabled
Since:
  • 0.4.0
Source:
lib/Client.js#L539

pieceLoaded

Emitted when a piece is loaded. (This can be spammy on bot startup or anytime you reload all of a piece type.)
Parameters:
Name Type Description
piece Piece The piece that was loaded
Since:
  • 0.4.0
Source:
lib/Client.js#L518

pieceReloaded

Emitted when a piece is reloaded.
Parameters:
Name Type Description
piece Piece The piece that was reloaded
Since:
  • 0.4.0
Source:
lib/Client.js#L532

pieceUnloaded

Emitted when a piece is unloaded.
Parameters:
Name Type Description
piece Piece The piece that was unloaded
Since:
  • 0.4.0
Source:
lib/Client.js#L525

settingUpdate

Emitted when SettingGateway.update, SettingGateway.updateArray or SettingGateway.reset is run.
Parameters:
Name Type Description
gateway SettingGateway The setting gateway with the updated setting
id string The identifier of the gateway that was updated
oldEntries Object The old settings entries
newEntries Object The new settings entries
Since:
  • 0.3.0
Source:
lib/Client.js#L508

verbose

An event for handling verbose logs
Parameters:
Name Type Description
data string | Object The data to log
Since:
  • 0.4.0
Source:
lib/Client.js#L457

wtf

An event for handling wtf logs (what a terrible failure)
Parameters:
Name Type Description
data string | Object The data to log
Since:
  • 0.4.0
Source:
lib/Client.js#L464