Client

The YAMDBF Client through which you can access storage and any of the properties available on a typical Discord.js Client instance

Constructor

new Client(options: YAMDBFOptions, clientOptions?: ClientOptions)

Parameters:
Name Type Attributes Description
options
YAMDBFOptions

Object containing required client properties

clientOptions
ClientOptions
<optional>

Discord.js ClientOptions

Source:

Extends

Events

blacklistAdd

Emitted whenever a user is blacklisted

Parameters:
Name Type Description
user
User

User who was blacklisted

global
boolean

Whether or not blacklisting is global

Source:

blacklistRemove

Emitted whenever a user is removed from the blacklist

Parameters:
Name Type Description
user
User

User who was removed

global
boolean

Whether or not removal is global

Source:

clientReady

Emitted when the client is ready. Should be used instead of Discord.js' ready event, as this is the point that everything is set up within the YAMDBF Client and it's all ready to go

Source:

command

Emitted whenever a command is successfully called

Parameters:
Name Type Description
name
string

Name of the called command

args
any[]

Args passed to the called command

execTime
number

Time command took to execute

message
Message

Message that triggered the command

Source:

continue

To be emitted after the pause event when you have finished setting things up that should be set up before the client is ready for use

Source:

noCommand

Emitted whenever a message is received that does not contain a command or unknown command

Parameters:
Name Type Description
message
Message

Message that did not contain a command or unknown command

Source:

pause

Emitted when the client is waiting for you to send a continue event, after which clientReady will be emitted

Source:

unknownCommand

Emitted whenever a command is called that doesn't exist

Parameters:
Name Type Description
name
string

The name of the command that was attempted to be called

args
any[]

Args passed to the unknown command

message
Message

Message that triggered the unknown command

Source:

Properties

.argsParser: function

The argument parsing function the framework will use to parse command arguments from message content input. Defaults to splitting on Command#argOpts.separator

Type:
function
Source:

.buttons: object

Button shortcuts for compact mode. Defaults are success, fail, and working. These can be overwritten via the buttons field in YAMDBFOptions

Type:
object
Source:

.commands: CommandRegistry<string, Command>

Collection containing all loaded commands

Type:
CommandRegistry<string, Command>
Source:

.commandsDir: string

Directory to find command class files. Optional if client is passive.
See: Client#passive

Type:
string
Source:

.compact: boolean

Whether or not compact mode is enabled

Type:
boolean
Source:

.defaultLang: string

Default language to use for localization

Type:
string
Source:

.disableBase: BaseCommandName[]

Array of base command names to skip when loading commands. Base commands may only be disabled by name, not by alias

Type:
BaseCommandName[]
Source:

.dmHelp: boolean

Whether or not the help command should send its output in a DM to the command caller

Type:
boolean
Source:

.eventLoader: EventLoader

The EventLoader the client uses to load events. The client will load events from the eventsdir directory passed in your YAMDBFOptions.

Can be used by plugins to register directories to load custom event handlers from

Type:
EventLoader
Source:

.eventsDir: string

Directory to find Event class files. Optional if client is passive.
See: Client#passive

Type:
string
Source:

.localeDir: string

Directory to find custom localization files

Type:
string
Source:

.owner: string[]

The owner/owners of the bot, represented as an array of IDs. These IDs determine who is allowed to use commands flagged as ownerOnly

Type:
string[]
Source:

.passive: boolean

Whether or not this client is passive. Passive clients will not register a command dispatcher or a message listener. This allows passive clients to be created that do not respond to any commands but are able to perform actions based on whatever the framework user wants

Type:
boolean
Source:

.pause: boolean

Whether or not the client will pause after loading Client Storage, giving the opportunity to add/change default settings before guild settings are created for the first time. If this is used, you must create a listener for 'pause', and call <Client>.continue() when you have finished doing what you need to do.

If adding new default settings is desired after guild settings have already been generated for the first time, they should be added after 'clientReady' so they can be properly pushed to the settings for all guilds

Type:
boolean
Source:

.plugins: PluginLoader

Loads plugins and contains loaded plugins in case accessing a loaded plugin at runtime is desired

Type:
PluginLoader
Source:

.provider: StorageProvider

The chosen storage provider to use for the Client. Defaults to JSONProvider

Type:
StorageProvider
Source:

.ratelimit: string

The global ratelimit for all command usage per user

Type:
string
Source:

.rateLimitManager: RateLimitManager

A convenient instance of RateLimitManager for use anywhere the Client is available

Type:
RateLimitManager
Source:

.readyText: string

Text to output when the client is ready. If not provided nothing will be logged, giving the opportunity to log something more dynamic on clientReady

Type:
string
Source:

.resolvers: ResolverLoader

ResolverLoader instance containing loaded argument resolvers

Type:
ResolverLoader
Source:

.statusText: string

Status text for the client

Type:
string
Source:

.storage: ClientStorage

Client-specific storage. Also contains a guilds Collection property containing all GuildStorage instances

Type:
ClientStorage
Source:

.tsNode: boolean

Whether or not ts-node is in use, allowing the Client to attempt to load .ts files when loading Commands

Type:
boolean
Source:

.unknownCommandError: boolean

Whether or not a generic 'command not found' message should be given in DMs to instruct the user to use the help command. true by default

Type:
boolean
Source:

Methods

.continue() → void

Shortcut method for <Client>.emit('continue')

Source:
Returns:
void

.createBotInvite() → Promise<string>

Generate a bot invite URL based on the permissions included in all of the commands the client currently has loaded.

Note: This should be run after clientReady to ensure no command permissions are missing from the permissions set that will be used to generate the URL

Source:
Returns:
Promise<string>

.defaultSettingExists(key: string) → Promise<boolean>

Check if a default guild setting exists

Parameters:
Name Type Description
key
string

The default settings key to check for

Source:
Returns:
Promise<boolean>

.getPrefix(guild: Guild) → Promise<string | null>

Shortcut to return the command prefix for the provided guild

Parameters:
Name Type Description
guild
Guild

The Guild to get the prefix of

Source:
Returns:
Promise<string | null>

.isOwner(user: User) → boolean

Returns whether or not the given user is an owner of the client/bot

Parameters:
Name Type Description
user
User

User to check

Source:
Returns:
boolean

.removeDefaultSetting(key: string) → Promise<Client>

Remove a defaultGuildSettings item. Will not remove from any current guild settings, but will remove the item from the defaults added to new guild settings storages upon creation

Parameters:
Name Type Description
key
string

The key to use in settings storage

Source:
Returns:
Promise<Client>

.setDefaultSetting(key: string, value: any) → Promise<Client>

Set the value of a default setting key and push it to all guild setting storages. Will not overwrite a setting in guild settings storage if there is already an existing key with the given value

Parameters:
Name Type Description
key
string

The key to use in settings storage

value
any

The value to use in settings storage

Source:
Returns:
Promise<Client>

.start()Client

Starts the login process, culminating in the clientReady event

Source:
Returns:
Client

.sweepStorages() → Promise<void>

Clean out expired guild storage/settings

Source:
Returns:
Promise<void>

.use(func: MiddlewareFunction)Client

Adds a middleware function to be used when any command is called to make modifications to args, determine if the command can be run, or anything else you want to do every time any command is called.

See MiddlewareFunction for information on how a middleware function should be represented

Usage example:

<Client>.use((message, args) => [message, args.map(a => a.toUpperCase())]);

This will add a middleware function to all commands that will attempt to transform all args to uppercase. This will of course fail if any of the args are not a string.

Note: Middleware functions should only be added to the client one time each and thus should not be added within any sort of event or loop. Multiple separate middleware functions can be added to the via multiple separate calls to this method

Warning: Do not use middleware for overriding the default argument splitting. Use YAMDBFOptions.argsParser instead. Otherwise you will see inconsistent results when using Command shortcuts, as argument splitting for shortcut interpolation always happens before middleware is run

Parameters:
Name Type Description
func
MiddlewareFunction

The middleware function to use

Source:
Returns:
Client