Documentation Index
Fetch the complete documentation index at: https://docs.sorionlib.dev/llms.txt
Use this file to discover all available pages before exploring further.
General
Why is my client not starting?
Check these common issues:
- Missing configuration - Ensure required options are set:
const client = new Sorion({
// Required for Discord bots
discord: {
token: process.env.DISCORD_TOKEN
}
});
-
Invalid token - Verify your Discord token is correct and not expired.
-
Missing intents - Discord requires specific intents:
const client = new Sorion({
discord: {
token: process.env.DISCORD_TOKEN,
intents: ["Guilds", "GuildMessages", "MessageContent"]
}
});
- Network issues - Check your internet connection and firewall settings.
How do I enable debug mode?
Set the debug option to true:
const client = new Sorion({
debug: true
});
Or use an environment variable:
SORION_DEBUG=true node index.js
Debug mode outputs detailed logs including:
- API request/response details
- Database queries
- Event emissions
- Internal state changes
Can I extend the event system?
Yes, you can create custom events:
import { Sorion, EventEmitter } from "sorionlib";
const client = new Sorion();
// Emit custom events
client.emit("customEvent", { data: "value" });
// Listen to custom events
client.on("customEvent", (payload) => {
console.log("Custom event received:", payload);
});
You can also create typed events with TypeScript:
interface MyEvents {
userCreated: (user: User) => void;
orderPlaced: (order: Order) => void;
}
const client = new Sorion<MyEvents>();
client.on("userCreated", (user) => {
// user is typed as User
});
Installation
What Node.js version is required?
Sorionlib requires Node.js 16.0.0 or higher. Check your version:
How do I update Sorionlib?
Or install a specific version:
npm install sorionlib@latest
Are there any peer dependencies?
No, Sorionlib bundles all required dependencies. However, for Discord functionality, you may want to install discord.js for additional features:
API client
How do I handle rate limiting?
The API client handles rate limiting automatically with retries. You can customize the behavior:
const api = new ApiClient({
baseUrl: "https://api.example.com",
retries: 5,
retryDelay: 1000 // Wait 1 second between retries
});
const api = new ApiClient({
baseUrl: "https://api.example.com",
headers: {
"X-Custom-Header": "value",
"Authorization": "Bearer token"
}
});
How do I handle file uploads?
const formData = new FormData();
formData.append("file", fileBuffer, "filename.png");
await api.post("/upload", formData, {
headers: {
"Content-Type": "multipart/form-data"
}
});
Database
How do I connect to multiple databases?
Create multiple instances:
const primaryDb = new MongoDB({
uri: process.env.PRIMARY_DB_URI,
database: "primary"
});
const secondaryDb = new MongoDB({
uri: process.env.SECONDARY_DB_URI,
database: "secondary"
});
await Promise.all([
primaryDb.connect(),
secondaryDb.connect()
]);
How do I handle connection failures?
Listen to connection events:
const db = new MongoDB({ uri: "...", database: "myapp" });
db.on("error", (error) => {
console.error("Database error:", error);
});
db.on("disconnected", async () => {
console.log("Disconnected, attempting reconnect...");
await db.reconnect();
});
db.on("reconnected", () => {
console.log("Reconnected successfully");
});
Discord
How do I register slash commands?
const bot = new DiscordBot({
token: process.env.DISCORD_TOKEN
});
// Add slash commands
bot.addCommand(
new Command()
.setName("ping")
.setSlash(true)
.setHandler(async (ctx) => {
await ctx.reply("Pong!");
})
);
// Register with Discord
await bot.registerSlashCommands();
bot.on("interactionCreate", async (interaction) => {
if (!interaction.isButton()) return;
if (interaction.customId === "confirm") {
await interaction.reply("Confirmed!");
}
});
How do I create embeds?
import { Embed } from "sorionlib";
const embed = new Embed()
.setTitle("Hello")
.setDescription("This is an embed")
.setColor("#00ff00")
.addField("Field 1", "Value 1")
.setFooter("Footer text");
await ctx.reply({ embeds: [embed] });
Troubleshooting
I’m getting “Cannot find module ‘sorionlib’”
Ensure Sorionlib is installed:
Check your import statement matches your module system:
// ES Modules
import { Sorion } from "sorionlib";
// CommonJS
const { Sorion } = require("sorionlib");
TypeScript types are not working
Ensure you have TypeScript 4.5 or higher:
npm install typescript@latest
Types are included in the package, no @types package needed.
Memory usage is high
- Close unused connections:
- Clear caches:
- Use streaming for large datasets:
const cursor = db.collection("users").find({}).cursor();
for await (const user of cursor) {
// Process one at a time
}