Installation
Install the Cordia SDK in your Discord bot project using your preferred language and package manager. We support both JS/Node.js and Python.
Requirements
- Node.js 18+ or Python 3.8+
- A Cordia account â Sign up at cordialane.com to get your API key.
Install the Package
JavaScript / TypeScript
npm
bash
npm install cordiayarn
bash
yarn add cordiapnpm
bash
pnpm add cordiaPython
pip
bash
pip install cordiaEnvironment Variables
đĄSecurity First
We recommend storing your API key and bot ID in environment variables (never hardcode them). Create a
.env file:.env
bash
CORDIA_API_KEY=your-api-key-here
CORDIA_BOT_ID=your-bot-id-here
# Optional: Override the API URL (defaults to https://api.cordialane.com/api/v1)
CORDIA_API_URL=https://cordlane-brain.onrender.com/api/v1Basic Setup & Examples
Discord.js Example
Here's a complete example integrating Cordia with a discord.js bot:
bot.ts
typescript
import { Client, GatewayIntentBits } from 'discord.js';
import { CordiaClient } from 'cordia';
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
});
// Create the client â heartbeat starts automatically!
const cordia = new CordiaClient({
apiKey: process.env.CORDIA_API_KEY!,
botId: process.env.CORDIA_BOT_ID!,
});
client.on('ready', async () => {
console.log(`â
Logged in as ${client.user?.tag}`);
await cordia.postGuildCount(client.guilds.cache.size);
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isChatInputCommand()) return;
// Track the command with Cordia
cordia.trackCommand({
command: interaction.commandName,
userId: interaction.user.id,
guildId: interaction.guildId ?? undefined,
});
});
// Graceful shutdown
process.on('SIGINT', async () => {
await cordia.destroy();
client.destroy();
process.exit(0);
});
client.login(process.env.DISCORD_TOKEN);Discord.py Example
Here's a complete example integrating Cordia with a python discord.py bot:
bot.py
python
import discord
from discord.ext import commands
import cordia
import os
intents = discord.Intents.default()
bot = commands.Bot(command_prefix="!", intents=intents)
# Initialize cordia client
cordia_client = cordia.CordiaClient(
api_key=os.getenv("CORDIA_API_KEY"),
bot_id=os.getenv("CORDIA_BOT_ID")
)
@bot.event
async def on_ready():
print(f"â
Logged in as {bot.user}")
await cordia_client.post_guild_count(len(bot.guilds))
# Start the async background heartbeat and queue processor
cordia_client.start(bot.loop)
@bot.command()
async def ping(ctx):
await ctx.send("Pong!")
# Track the command with Cordia
await cordia_client.track_command(
command="ping",
user_id=str(ctx.author.id),
guild_id=str(ctx.guild.id) if ctx.guild else None
)
bot.run(os.getenv("DISCORD_TOKEN"))âšī¸What happens on init?
When you initialize the
CordiaClient and start it, these things happen automatically:- â Config is validated
- â Heartbeat starts pinging in the background
- â Event queue is initialized for automatic batching and sending
Next Steps
Now that you have the SDK installed, learn how to configure it for your needs.