Appearance
Client
Package: @erinjs/core
Main erin.js bot client. Connects to the gateway, emits events, and provides REST access.
Constructor
| Name | Type | Optional | Description |
|---|---|---|---|
options | ClientOptions | No | Token, REST config, WebSocket, presence, etc. |
Properties
| Name | Type | Readonly | Optional | Description |
|---|---|---|---|---|
channels | ChannelManager | Yes | No | |
events | ClientEventMethods | Yes | No | Typed event handlers. Use client.events.MessageReactionAdd((reaction, user, messageId, channelId, emoji, userId) => {...}) or client.on(Events.MessageReactionAdd, ...). |
guilds | GuildManager | Yes | No | |
readyAt | Date | null | No | No | Timestamp when the client became ready. Null until READY is received. |
rest | REST | Yes | No | |
Routes | any | Yes | No | |
user | ClientUser | null | No | No | The authenticated bot user. Null until READY is received. |
users | UsersManager | Yes | No | |
ws | WebSocketManager | Yes | No | WebSocket 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:
| Name | Type | Optional | Description |
|---|---|---|---|
emojiId | string | No | |
guildId | string | No |
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:
| Name | Type | Optional | Description |
|---|---|---|---|
channelId | string | No | Snowflake of the channel |
messageId | string | No | Snowflake 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:
| Name | Type | Optional | Description |
|---|---|---|---|
data | APIUserPartial | No |
handleDispatch() async
Returns: Promise<void>
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
payload | GatewayReceivePayload | No |
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:
| Name | Type | Optional | Description |
|---|---|---|---|
token | string | No | Bot 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:
| Name | Type | Optional | Description |
|---|---|---|---|
emoji | string | { name: string; id?: string; animated?: boolean; } | No | Emoji string or object |
guildId | string | null | Yes | Guild 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:
| Name | Type | Optional | Description |
|---|---|---|---|
channelId | string | No | |
payload | string | MessageSendOptions | No |
sendToGateway()
Send a payload to the gateway (e.g. Voice State Update).
Returns: void
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
shardId | number | No | Shard ID (use 0 for single-shard) |
payload | GatewaySendPayload | No | Gateway payload to send |