Skip to content

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";
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],
});
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.

Connects to Discord.

await client.login();

Permanently closes the Gateway connection.

client.destroy();

Returns true if the client is in the "ready" state.

if (client.isReady()) {
console.log("Bot is online!");
}
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! ๐Ÿ‘‹" });
}
});
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();