A minimal Discord bot that routes messages directly to LM Studio — no OpenClaw gateway in the path.
text
Discord → bot.js → LM Studio API → bot.js → Discord
The bot uses Discord.js to receive messages and axios to call LM Studio's /v1/chat/completions endpoint directly. No tools, no workspace files, no system prompt overhead.
bash
mkdir lm-studio-discord-bot
cd lm-studio-discord-bot
npm init -y
npm install discord.js axios
See scripts/bot-template.js for the ready-to-use template.
Edit these constants in bot.js:
javascript
const DISCORD_TOKEN = 'YOUR_DISCORD_BOT_TOKEN';
const LM_STUDIO_URL = 'http://127.0.0.1:1234/v1/chat/completions';
const MODEL = 'qwen2-0.5b-instruct'; // Must match loaded model in LM Studio
const GUILD_ID = 'YOUR_DISCORD_SERVER_ID';
To get your bot token: https://discord.com/developers/applications
To get the Guild ID: Enable Developer Mode in Discord → Right-click your server → Copy ID
text
https://discord.com/oauth2/authorize?client_id=BOT_CLIENT_ID&permissions=1024&scope=bot
Replace BOT_CLIENT_ID with your bot's Application ID from the Discord Developer Portal.
bash
node bot.js
The bot will log in and respond to messages in any channel of the configured guild.
ParameterDefaultNotesmax_tokens512Lower = faster, less verbosetimeout60000msIncrease if slow on CPUstream``falseSet true for streaming replies
To add conversation history, modify the messages array in the axios call to include prior exchanges. Note: this increases token usage and context window pressure.