Client Options
When creating a ForgeClient, you can pass an options object to pick your gateway intents, listen to specific Discord events, set prefixes, and load extensions.
| Option | Description |
|---|---|
intents |
Gateway intents your bot needs, like ["Guilds", "GuildMessages"]. |
events |
Discord events to listen to, like ["messageCreate", "interactionCreate"]. |
prefixes |
Prefix strings the bot responds to for text commands, like ["!"]. |
extensions |
Official or custom extensions loaded on startup, like [new ForgeDB()]. |
Extensions
Extensions add functionality like databases, audio nodes, or canvas editing without adding clutter to the core library. Here are three common setups:
const { ForgeClient } = require("@tryforge/forgescript")
const { ForgeDB } = require("@tryforge/forge.db")
const client = new ForgeClient({
intents: ["Guilds", "GuildMessages"],
events: ["messageCreate"],
prefixes: ["!"],
extensions: [new ForgeDB()],
}) const { ForgeClient } = require("@tryforge/forgescript")
const { ForgeLinked } = require("@tryforge/forge.linked")
const client = new ForgeClient({
intents: ["Guilds", "GuildVoiceStates"],
events: ["interactionCreate"],
extensions: [
new ForgeLinked({
nodes: [{ name: "main", host: "localhost", port: 2333, auth: "youshallnotpass" }],
}),
],
}) const { ForgeClient } = require("@tryforge/forgescript")
const { ForgeCanvas } = require("@tryforge/forge.canvas")
const client = new ForgeClient({
intents: ["Guilds", "GuildMessages"],
events: ["messageCreate"],
prefixes: ["!"],
extensions: [new ForgeCanvas()],
}) Loading Commands from Folders
Instead of writing every command in index.js, you can organize them into separate files inside a dedicated folder:
// In your index.js
client.commands.load("./commands") You can also pass commands: "./commands" directly in your ForgeClient options.
Creating a command file
Create a commands folder in your project root, and add a .js file inside it (for example, commands/ping.js):
module.exports = {
type: "messageCreate",
name: "ping",
code: `Pong! $ping ms`,
} You can also export an array of commands from a single file if you prefer grouping related commands together:
module.exports = [
{
type: "messageCreate",
name: "ping",
code: `Pong! $ping ms`,
},
{
type: "messageCreate",
name: "hello",
code: `Hello, $username!`,
},
] Application / Slash commands
For slash commands, point client.applicationCommands.load to your slash command folder:
client.applicationCommands.load("./slashes")