Client
The Client class is the primary entry point for building a Lunibee bot. It coordinates the REST API transport, Gateway WebSocket connection, resource caches, and event system.
import { Client } from "lunibee";import { Client } from "lunibee";Constructor
Section titled โConstructorโnew Client(options: ClientOptions)| Parameter | Type | Description |
|---|---|---|
options.token |
string |
Required. Discord bot token. |
options.intents |
GatewayIntentResolvable |
Required. Gateway intents to subscribe to. |
options.rest |
RESTOptions |
Optional REST client configuration. |
options.gateway |
GatewayOptions |
Optional Gateway configuration. |
import { Client, IntentBits } from "lunibee";
const client = new Client({ token: process.env.DISCORD_TOKEN!, intents: [IntentBits.guilds, IntentBits.guildMessages, IntentBits.messageContent],});import { Client, IntentBits } from "lunibee";
const client = new Client({ token: process.env.DISCORD_TOKEN, intents: [IntentBits.guilds, IntentBits.guildMessages, IntentBits.messageContent],});Properties
Section titled โPropertiesโ| Property | Type | Description |
|---|---|---|
client.rest |
REST |
Low-level REST transport. |
client.ws / client.gateway |
Gateway |
Active Gateway WebSocket connection. |
client.users |
UserManager |
User cache and fetcher. |
client.guilds |
GuildManager |
Guild cache and fetcher. |
client.channels |
ChannelManager |
Channel cache and fetcher. |
client.application.commands |
ApplicationCommandManager |
Application command manager. |
client.user |
ClientUser | undefined |
Authenticated bot user (available after ready). |
client.state |
ClientState |
Current lifecycle state: "idle", "connecting", "ready", or "destroyed". |
client.ping |
number |
Current WebSocket heartbeat latency in ms. |
client.uptime |
number | null |
Milliseconds since the client became ready, or null. |
client.token |
string | null |
The bot token, or null once destroyed. |
client.readyAt |
Date | undefined |
When the client last became ready. |
Methods
Section titled โMethodsโlogin(token?)
Section titled โlogin(token?)โConnects to Discord.
await client.login();await client.login();destroy()
Section titled โdestroy()โPermanently closes the Gateway connection.
client.destroy();isReady()
Section titled โisReady()โReturns true if the client is in the "ready" state.
if (client.isReady()) { console.log("Bot is online!");}if (client.isReady()) { console.log("Bot is online!");}setPresence(data)
Section titled โsetPresence(data)โclient.setPresence({ status: "online", activities: [{ name: "custom_status", state: "๐ Buzzing!", type: 4 }],});client.setPresence({ status: "online", activities: [{ name: "custom_status", state: "๐ Buzzing!", type: 4 }],});client.on("ready", (user) => { console.log(`๐ Logged in as ${user.username}!`);});
client.on("messageCreate", async (message) => { if (message.content === "!ping") { await message.reply("Pong! ๐"); }});
client.on("interactionCreate", async (interaction) => { if (interaction.isChatInputCommand() && interaction.commandName === "hello") { await interaction.reply({ content: "Hello! ๐" }); }});client.on("ready", (user) => { console.log(`๐ Logged in as ${user.username}!`);});
client.on("messageCreate", async (message) => { if (message.content === "!ping") { await message.reply("Pong! ๐"); }});
client.on("interactionCreate", async (interaction) => { if (interaction.isChatInputCommand() && interaction.commandName === "hello") { await interaction.reply({ content: "Hello! ๐" }); }});Full Example
Section titled โFull Exampleโimport { Client, IntentBits, EmbedBuilder } from "lunibee";
const client = new Client({ token: process.env.DISCORD_TOKEN!, intents: [IntentBits.guilds, IntentBits.guildMessages, IntentBits.messageContent],});
client.on("ready", (user) => { console.log(`๐ Ready as ${user.username}`);});
client.on("messageCreate", async (message) => { if (message.author.bot) return; if (message.content === "!status") { const embed = new EmbedBuilder() .setTitle("Bot Status") .addFields( { name: "Ping", value: `${client.ping}ms`, inline: true }, { name: "Uptime", value: `${Math.floor((client.uptime ?? 0) / 1000)}s`, inline: true }, ) .setColor(0xf59e0b); await message.reply({ embeds: [embed] }); }});
await client.login();import { Client, IntentBits, EmbedBuilder } from "lunibee";
const client = new Client({ token: process.env.DISCORD_TOKEN, intents: [IntentBits.guilds, IntentBits.guildMessages, IntentBits.messageContent],});
client.on("ready", (user) => { console.log(`๐ Ready as ${user.username}`);});
client.on("messageCreate", async (message) => { if (message.author.bot) return; if (message.content === "!status") { const embed = new EmbedBuilder() .setTitle("Bot Status") .addFields( { name: "Ping", value: `${client.ping}ms`, inline: true }, { name: "Uptime", value: `${Math.floor((client.uptime ?? 0) / 1000)}s`, inline: true }, ) .setColor(0xf59e0b); await message.reply({ embeds: [embed] }); }});
await client.login();