Skip to main content

Class: Client

index.Client

Hierarchy​

Constructors​

constructor​

• new Client(name, commandPrefixes?, options?): Client

Creates a new msgroom client.

Parameters​

NameTypeDefault valueDescription
namestringundefinedThe username to use.
commandPrefixesstring | RegExp | (string | RegExp)[][]List of prefixes to be used for commands. Set this to an empty string to disable the command system.
optionsPartial<ClientOptions>{}Extra options.

Returns​

Client

Overrides​

(EventEmitter as unknown as new () =&gt; TypedEmitter.default&lt;ClientEvents&gt;).constructor

Defined in​

src/index.ts:63

Properties​

#ID​

• Private Optional #ID: string

Defined in​

src/index.ts:43


#name​

• Private #name: string

Defined in​

src/index.ts:27


#sessionID​

• Private Optional #sessionID: string

Defined in​

src/index.ts:44


apikey​

• Optional apikey: string

Defined in​

src/index.ts:35


authOptions​

• authOptions: undefined | Omit<Partial<{ apikey?: string ; bot?: boolean ; loginkey?: string ; staff?: string ; user: string }>, "bot" | "user" | "apikey">

Cannot be changed after connecting.

Defined in​

src/index.ts:52


blockBots​

• blockBots: boolean

Defined in​

src/index.ts:48


blockSelf​

• blockSelf: boolean

Defined in​

src/index.ts:32


blockedIDs​

• blockedIDs: Set<string>

Defined in​

src/index.ts:45


blockedSessionIDs​

• blockedSessionIDs: Set<string>

Defined in​

src/index.ts:46


bot​

• bot: boolean

Defined in​

src/index.ts:47


commands​

• commands: CommandMap = {}

Defined in​

src/index.ts:54


erroredFiles​

• erroredFiles: Set<string>

Defined in​

src/index.ts:55


helpCommandLimit​

• helpCommandLimit: number

Defined in​

src/index.ts:37


helpSuffix​

• helpSuffix: string

Defined in​

src/index.ts:31


mainPrefix​

• mainPrefix: string | RegExp

Defined in​

src/index.ts:40


prefixes​

• prefixes: Set<string | RegExp>

Defined in​

src/index.ts:39


printErrors​

• printErrors: boolean

Defined in​

src/index.ts:30


server​

• server: string

Defined in​

src/index.ts:28


socket​

• Optional socket: MsgroomSocket

Defined in​

src/index.ts:26


socketIOOptions​

• socketIOOptions: undefined | Partial<ManagerOptions & SocketOptions>

Cannot be changed after connecting.

Defined in​

src/index.ts:50


unescapeMessages​

• unescapeMessages: boolean

Defined in​

src/index.ts:36


users​

• users: Record<string, User> = {}

Defined in​

src/index.ts:42


welcomeMessage​

• Optional welcomeMessage: string

Deprecated

This option has been removed. As a general rule, bots should not send messages if the user doesn't explicitly ask for them.

Defined in​

src/index.ts:34

Accessors​

ID​

• get ID(): string

The user's ID.

Returns​

string

Throws

A NotConnectedError when you haven't connected yet.

Defined in​

src/index.ts:190


name​

• get name(): string

The user's name. You can change it by reassigning this variable. Do note that changing it is done using an asynchronous operation, meaning the change won't be reflected immediately.

Returns​

string

Throws

A NotConnectedError when you haven't connected yet.

Defined in​

src/index.ts:175

• set name(name): void

Parameters​

NameType
namestring

Returns​

void

Defined in​

src/index.ts:179


sessionID​

• get sessionID(): string

The user's session ID.

Returns​

string

Throws

A NotConnectedError when you haven't connected yet.

Defined in​

src/index.ts:199

Methods​

addListener​

▸ addListener<E>(event, listener): Client

Type parameters​

NameType
Eextends keyof ClientEvents

Parameters​

NameType
eventE
listenerClientEvents[E]

Returns​

Client

Inherited from​

(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).addListener

Defined in​

node_modules/typed-emitter/index.d.ts:22


adminAction​

▸ adminAction(...args): void

Triggers an admin action. The way it works is by passing an array of arguments, similar to how commands work. We currently have no idea what these commands could be because only msgroom staff know the list of commands.

Parameters​

NameTypeDescription
...argsstring[]The arguments to pass to the admin-action event.

Returns​

void

Throws

A NotConnectedError when you haven't connected yet.

Defined in​

src/index.ts:233


connect​

▸ connect(): Promise<void>

Connect to a msgroom server.

Returns​

Promise<void>

A promise which resolves when the connection has successfully been established.

Throws

An AuthError when the server won't let you in.

Defined in​

src/index.ts:101


disconnect​

▸ disconnect(): void

Disconnects from the server if connected.

Returns​

void

Defined in​

src/index.ts:165


emit​

▸ emit<E>(event, ...args): boolean

Type parameters​

NameType
Eextends keyof ClientEvents

Parameters​

NameType
eventE
...argsParameters<ClientEvents[E]>

Returns​

boolean

Inherited from​

(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).emit

Defined in​

node_modules/typed-emitter/index.d.ts:32


eventNames​

▸ eventNames(): (string | symbol)[]

Returns​

(string | symbol)[]

Inherited from​

(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).eventNames

Defined in​

node_modules/typed-emitter/index.d.ts:34


getCommand​

▸ getCommand(commandAndArguments): Promise<undefined | [CommandWithName, string[]]>

Gets a command from its call.

Parameters​

NameTypeDescription
commandAndArgumentsstring[]The split arguments which also have the command in it.

Returns​

Promise<undefined | [CommandWithName, string[]]>

A promise which resolves to the command and its arguments, or undefined if none was found.

Defined in​

src/index.ts:243


getMaxListeners​

▸ getMaxListeners(): number

Returns​

number

Inherited from​

(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).getMaxListeners

Defined in​

node_modules/typed-emitter/index.d.ts:39


isBlocked​

▸ isBlocked(userID, userSessionID?, blockBots?): boolean

Checks whether the specified user is blocked.

Parameters​

NameTypeDescription
userIDstringA user's ID or an object with an ID, sessionID, and/or blockBots property.
userSessionID?stringA user's session ID.
blockBots?booleanWhether to block bots too. Defaults to the blockBots option.

Returns​

boolean

A boolean value indicating whether the user is blocked.

Example

client.isBlocked("user-id-here", "session-id-here");
client.isBlocked({
ID: "user-id-here", // you can leave any of these out
sessionID: "session-id-here",
blockBots: true,
});

client.isBlocked("bad-user-id", "some session id"); // false
client.blockedIDs.add("bad-user-id");
client.isBlocked("bad-user-id", "some session id"); // true

Defined in​

src/index.ts:498

▸ isBlocked(userIDOrObject): boolean

Parameters​

NameType
userIDOrObjectObject
userIDOrObject.ID?string
userIDOrObject.blockBots?boolean
userIDOrObject.sessionID?string

Returns​

boolean

Defined in​

src/index.ts:499


isBot​

▸ isBot(sessionID): boolean

Parameters​

NameType
sessionIDstring

Returns​

boolean

Defined in​

src/index.ts:476


listenerCount​

▸ listenerCount<E>(event): number

Type parameters​

NameType
Eextends keyof ClientEvents

Parameters​

NameType
eventE

Returns​

number

Inherited from​

(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).listenerCount

Defined in​

node_modules/typed-emitter/index.d.ts:37


listeners​

▸ listeners<E>(event): ClientEvents[E][]

Type parameters​

NameType
Eextends keyof ClientEvents

Parameters​

NameType
eventE

Returns​

ClientEvents[E][]

Inherited from​

(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).listeners

Defined in​

node_modules/typed-emitter/index.d.ts:36


loadDirectory​

▸ loadDirectory(directory): Promise<void>

Loads modules from a directory recursively. Any errors thrown anywhere in the process will be caught and logged to the console.

Parameters​

NameTypeDescription
directorystring | URLThe directory to get the modules from.

Returns​

Promise<void>

A promise which resolves once the modules have been loaded.

Defined in​

src/index.ts:465


loadModule​

▸ loadModule(file): Promise<void>

Loads a module. Any errors thrown anywhere in the process will be caught and logged to the console.

Parameters​

NameTypeDescription
filestring | URLThe module to load.

Returns​

Promise<void>

A promise which resolves once the module has been loaded.

Defined in​

src/index.ts:403


off​

▸ off<E>(event, listener): Client

Type parameters​

NameType
Eextends keyof ClientEvents

Parameters​

NameType
eventE
listenerClientEvents[E]

Returns​

Client

Inherited from​

(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).off

Defined in​

node_modules/typed-emitter/index.d.ts:28


on​

▸ on<E>(event, listener): Client

Type parameters​

NameType
Eextends keyof ClientEvents

Parameters​

NameType
eventE
listenerClientEvents[E]

Returns​

Client

Inherited from​

(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).on

Defined in​

node_modules/typed-emitter/index.d.ts:23


once​

▸ once<E>(event, listener): Client

Type parameters​

NameType
Eextends keyof ClientEvents

Parameters​

NameType
eventE
listenerClientEvents[E]

Returns​

Client

Inherited from​

(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).once

Defined in​

node_modules/typed-emitter/index.d.ts:24


parseCommandCall​

▸ parseCommandCall(commandCall): string[]

Parameters​

NameType
commandCallstring

Returns​

string[]

Defined in​

src/index.ts:316


prependListener​

▸ prependListener<E>(event, listener): Client

Type parameters​

NameType
Eextends keyof ClientEvents

Parameters​

NameType
eventE
listenerClientEvents[E]

Returns​

Client

Inherited from​

(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).prependListener

Defined in​

node_modules/typed-emitter/index.d.ts:25


prependOnceListener​

▸ prependOnceListener<E>(event, listener): Client

Type parameters​

NameType
Eextends keyof ClientEvents

Parameters​

NameType
eventE
listenerClientEvents[E]

Returns​

Client

Inherited from​

(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).prependOnceListener

Defined in​

node_modules/typed-emitter/index.d.ts:26


processCommands​

▸ processCommands(context): Promise<void>

Processes a message to check for command calls.

Parameters​

NameTypeDescription
contextCommandContextThe context which will be passed to command handlers.

Returns​

Promise<void>

A promise which resolves when the associated command (if there is one) has been called.

Defined in​

src/index.ts:344


rawListeners​

▸ rawListeners<E>(event): ClientEvents[E][]

Type parameters​

NameType
Eextends keyof ClientEvents

Parameters​

NameType
eventE

Returns​

ClientEvents[E][]

Inherited from​

(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).rawListeners

Defined in​

node_modules/typed-emitter/index.d.ts:35


removeAllListeners​

▸ removeAllListeners<E>(event?): Client

Type parameters​

NameType
Eextends keyof ClientEvents

Parameters​

NameType
event?E

Returns​

Client

Inherited from​

(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).removeAllListeners

Defined in​

node_modules/typed-emitter/index.d.ts:29


removeListener​

▸ removeListener<E>(event, listener): Client

Type parameters​

NameType
Eextends keyof ClientEvents

Parameters​

NameType
eventE
listenerClientEvents[E]

Returns​

Client

Inherited from​

(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).removeListener

Defined in​

node_modules/typed-emitter/index.d.ts:30


runCommand​

▸ runCommand(command, commandHandlerArguments, context): Promise<void>

Runs a command.

Parameters​

NameTypeDescription
commandCommandWithNameThe command to run.
commandHandlerArgumentsstring[]The arguments to pass to the command's handler.
contextCommandContextThe context in which the command was triggered.

Returns​

Promise<void>

A promise which resolves when the command has been ran.

Defined in​

src/index.ts:294


sendMessage​

▸ sendMessage(...messages): void

Sends a message. (The character limit is 2048.) All arguments will be joined together with a space before being sent. Anything that is not a string will be converted to one, but this does not mean that it is a good practice to do so.

Parameters​

NameTypeDescription
...messagesstring[]The message to send.

Returns​

void

Throws

A NotConnectedError when you haven't connected yet.

Defined in​

src/index.ts:211


setMaxListeners​

▸ setMaxListeners(maxListeners): Client

Parameters​

NameType
maxListenersnumber

Returns​

Client

Inherited from​

(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).setMaxListeners

Defined in​

node_modules/typed-emitter/index.d.ts:40


validateNickname​

▸ validateNickname(name, onJoin?): void

Validates a nickname. A nickname should be 1-16 characters.

Parameters​

NameTypeDefault valueDescription
namestringundefinedThe nickname to validate.
onJoinbooleanfalseWhether the nickname is passed to the auth event, which checks for a length of 18 characters.

Returns​

void

Throws

An Error when the criteria has not been met.

Defined in​

src/index.ts:156


walkCommandOrMap​

▸ walkCommandOrMap(commandOrMap, walkFunction, fullCommand?): void

Walks a commandMap or a command's subcommands recursively.

Parameters​

NameTypeDefault valueDescription
commandOrMapCommand | CommandMapundefinedThe command or commandMap to walk.
walkFunctionWalkFunctionundefinedThe function that will be called with every command.
fullCommandstring[][]The full path to the current command or commandMap being walked. (Used when walking, you probably don't need this).

Returns​

void

Throws

An Error when fullCommand is empty when commandOrMap is a command.

Defined in​

src/index.ts:375