The Discord way
- Register a bot application in the Discord Developer Portal and configure gateway intents.
- Manage a persistent WebSocket connection to Discord's gateway (reconnection, heartbeats, session resumption).
- Request the right combination of intents: Guilds, GuildMessages, MessageContent (privileged intent requiring approval).
- Parse Discord-specific message objects (embeds, components, interactions vs. messages).
- Handle slash command registration separately from message events.
discord-agent.tsTypeScript
import { Client, GatewayIntentBits } from "discord.js"; const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, ], }); client.on("messageCreate", async (message) => { if (message.author.bot) return; const reply = await yourAgent(message.content); await message.reply(reply); }); client.login(process.env.DISCORD_TOKEN);
discord_agent.pyPython
import discord intents = discord.Intents.default() intents.message_content = True client = discord.Client(intents=intents) @client.event async def on_message(message): if message.author.bot: return reply = await your_agent(message.content) await message.reply(reply) client.run(os.environ["DISCORD_TOKEN"])
The RouteKit way
Configure Discord as a channel in the RouteKit dashboard. Your agent code is the same whether messages come from Discord or any other channel.
agent.tsTypeScript
import { RouteKit } from "routekit"; const routeKit = new RouteKit(); routeKit.on("message", async (msg) => { const reply = await yourAgent(msg.text); await msg.reply(reply); });
What you skip
No discord.js or discord.py dependency. No Discord-specific auth flow or message parsing. If you later add other channels, your code does not change.
Try it out
RouteKit is currently in beta. Join the waitlist to connect your agent to Discord and every other messaging channel with one integration. Or read more about why RouteKit.