Skip to content

Client

Package: @erinjs/core

Main erin.js bot client. Connects to the gateway, emits events, and provides REST access.

Constructor

NameTypeOptionalDescription
optionsClientOptionsNoToken, REST config, WebSocket, presence, etc.

Properties

NameTypeReadonlyOptionalDescription
channelsChannelManagerYesNo
eventsClientEventMethodsYesNoTyped event handlers. Use client.events.MessageReactionAdd((reaction, user, messageId, channelId, emoji, userId) => {...}) or client.on(Events.MessageReactionAdd, ...).
guildsGuildManagerYesNo
readyAtDate | nullNoNoTimestamp when the client became ready. Null until READY is received.
restRESTYesNo
RoutesanyYesNo
userClientUser | nullNoNoThe authenticated bot user. Null until READY is received.
usersUsersManagerYesNo
wsWebSocketManagerYesNoWebSocket manager. Throws if not logged in.

Methods

assertEmojiInGuild() async

Asserts that a custom emoji (by id) belongs to the given guild. Used when reacting in guild channels to reject emojis from other servers.

Returns: Promise<void>

Parameters:

NameTypeOptionalDescription
emojiIdstringNo
guildIdstringNo

assertReady()

Throws if the client is not ready. Use before accessing client.user or other post-ready state.

Returns: void

Parameters:

None


destroy() async

Disconnect from the gateway and clear cached data.

Returns: Promise<void>

Parameters:

None


fetchInstance() async

Fetch instance info (API URL, gateway URL, features). GET /instance. Does not require authentication.

Returns: Promise<APIInstance>

Parameters:

None


fetchMessage() async

Fetch a message by channel and message ID. Use when you have IDs (e.g. from a DB).

Returns: Promise<Message>

Parameters:

NameTypeOptionalDescription
channelIdstringNoSnowflake of the channel
messageIdstringNoSnowflake of the message

getOrCreateUser()

Get or create a User from API data. Caches in client.users. Updates existing user's username, avatar, etc. when fresh data is provided.

Returns: User

Parameters:

NameTypeOptionalDescription
dataAPIUserPartialNo

handleDispatch() async

Returns: Promise<void>

Parameters:

NameTypeOptionalDescription
payloadGatewayReceivePayloadNo

isReady()

Returns true if the client has received Ready and user is set.

Returns: boolean

Parameters:

None


login() async

Connect to the erin.js gateway and authenticate.

Returns: Promise<string>

Parameters:

NameTypeOptionalDescription
tokenstringNoBot token (e.g. from FLUXER_BOT_TOKEN)

resolveEmoji() async

Resolve an emoji argument to the API format (unicode or "name:id"). Supports: <:name:id>, :name:, name:id, { name, id }, unicode. When id is missing (e.g. :name:), fetches guild emojis if guildId provided. When reacting in a guild channel, custom emojis must be from that guild.

Returns: Promise<string>

Parameters:

NameTypeOptionalDescription
emojistring | { name: string; id?: string; animated?: boolean; }NoEmoji string or object
guildIdstring | nullYesGuild ID for resolving custom emoji by name (required when id is missing)

sendToChannel() async

Send a message to any channel by ID. Shorthand for client.channels.send(). Works even when the channel is not cached.

Returns: Promise<Message>

Parameters:

NameTypeOptionalDescription
channelIdstringNo
payloadstring | MessageSendOptionsNo

sendToGateway()

Send a payload to the gateway (e.g. Voice State Update).

Returns: void

Parameters:

NameTypeOptionalDescription
shardIdnumberNoShard ID (use 0 for single-shard)
payloadGatewaySendPayloadNoGateway payload to send

Released under the Apache-2.0 License.