Skip to Content

Discord Bot

TL;DR

The Discord channel for @cmdop/bot uses discord.js to connect your CMDOP machines to Discord with slash commands. Create an application at the Discord Developer Portal, configure DiscordChannel with your bot token and guild IDs, then run commands like /shell, /agent, and /ls. Supports rich embeds, ephemeral messages, deferred responses, and guild-specific or global command sync.

Control your CMDOP machines from Discord with slash commands. Built on discord.js .

How do I set up a Discord bot?

  1. Create application at Discord Developer Portal 
  2. Create a bot and get the token
  3. Invite bot to your server with appropriate permissions

How do I install @cmdop/bot for Discord?

# Install the @cmdop/bot package (Discord adapter is included) npm install @cmdop/bot

How do I use the Discord channel?

// Import the hub and Discord-specific channel adapter import { IntegrationHub } from '@cmdop/bot'; import { DiscordChannel } from '@cmdop/bot/discord'; // Create the hub with your CMDOP API key and default target machine const hub = new IntegrationHub({ apiKey: process.env.CMDOP_API_KEY!, machine: 'my-server', }); // Add DiscordChannel with bot token and guild IDs for faster slash command sync hub.addChannel(new DiscordChannel({ token: process.env.DISCORD_BOT_TOKEN!, guildIds: ['123456789'], })); // Start the bot and begin listening for Discord slash commands hub.start();

What are the DiscordChannel options?

OptionTypeRequiredDescription
tokenstringYesDiscord bot token
guildIdsstring[]NoGuild IDs for faster slash command sync. Omit for global
allowedUsersstring[]NoAllowed Discord user IDs
timeoutnumberNoCommand timeout in milliseconds (default: 30000)

What commands can I use in Discord?

CommandDescription
/helpShow available commands
/shell <command>Execute shell command
/agent <task>Run AI agent task
/ls [path]List directory
/cat <path>Read file
/machine <hostname>Set target machine
/statusShow connection status

What features does the Discord channel support?

  • Slash commands with discord.js
  • Rich embeds for formatted output
  • Ephemeral messages for sensitive data
  • Deferred responses for slow operations
  • Guild-specific command sync

What is the difference between guild and global commands?

// Guild-specific: commands sync instantly, recommended for development/testing hub.addChannel(new DiscordChannel({ token: '...', guildIds: ['123456789', '987654321'], })); // Global: commands take up to 1 hour to sync across all servers hub.addChannel(new DiscordChannel({ token: '...', // No guildIds = global commands }));

What environment variables do I need?

# Discord bot token from the Developer Portal export DISCORD_BOT_TOKEN="your-bot-token" # Your CMDOP API key for authenticating with the CMDOP service export CMDOP_API_KEY="cmdop_xxx" # Default machine hostname to target for commands export CMDOP_MACHINE="my-server" # Guild ID for faster slash command sync (optional) export DISCORD_GUILD_ID="123456789"

How do I add permissions to my Discord bot?

// Import PermissionManager and PermissionLevel alongside the hub and channel import { IntegrationHub, PermissionManager, PermissionLevel } from '@cmdop/bot'; import { DiscordChannel } from '@cmdop/bot/discord'; // Create a permission manager instance const permissions = new PermissionManager(); // Grant full admin access to a specific Discord user permissions.addAdmin('discord:123456789'); // Grant EXECUTE-level access to another user on a specific machine permissions.grant({ identity: 'discord:555555555', machine: 'dev-server', level: PermissionLevel.EXECUTE, }); // Pass the permission manager to the hub const hub = new IntegrationHub({ apiKey: process.env.CMDOP_API_KEY!, permissions, }); // Add the Discord channel (no allowedUsers needed — permissions handle access) hub.addChannel(new DiscordChannel({ token: process.env.DISCORD_BOT_TOKEN!, })); hub.start();

What does a full Discord bot example look like?

// Full production-ready Discord bot setup import { IntegrationHub } from '@cmdop/bot'; import { DiscordChannel } from '@cmdop/bot/discord'; // Create hub using environment variables for configuration const hub = new IntegrationHub({ apiKey: process.env.CMDOP_API_KEY!, machine: process.env.CMDOP_MACHINE, }); // Conditionally set guildIds from env var (undefined means global commands) hub.addChannel(new DiscordChannel({ token: process.env.DISCORD_BOT_TOKEN!, guildIds: process.env.DISCORD_GUILD_ID ? [process.env.DISCORD_GUILD_ID] : undefined, })); // Start the bot and log confirmation hub.start().then(() => { console.log('Discord bot is running'); });

What bot permissions are required?

When inviting the bot, ensure these permissions:

  • Send Messages
  • Use Slash Commands
  • Embed Links (for rich embeds)
Last updated on