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:

pause

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

Source:

Properties

.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:

.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:

.localeDir

Directory to find custom localization files

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 emit '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:

.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:

.selfbot: boolean

Whether or not the client is a selfbot

Type:
boolean
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:

.unknownCommandError: string

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:
string
Source:

Methods

.continue() → void

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

Source:
Returns:
void

.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

.loadCommand(command: string) → void

Loads/reloads all/specific commands

Parameters:
Name Type Description
command
string

The name of a command to reload, or 'all' to load all commands

Source:
Returns:
void

.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() → void

Clean out any guild storage/settings that no longer have an associated guild

Source:
Returns:
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

Parameters:
Name Type Description
func
MiddlewareFunction

The middleware function to use

Source:
Returns:
Client