Setting Up Your Agent Environment
Communication Channels: Telegram & Discord
An agent without a communication channel is like a brilliant assistant locked in a room with no door. You need a way to talk to your agent — and more importantly, a way for your agent to reach you. Telegram and Discord are the two most practical channels for agent communication, each with distinct strengths.
Why These Two Channels
Telegram is ideal for personal, one-on-one agent interaction. It works on every device, supports rich media (photos, documents, voice notes), and its Bot API is one of the most straightforward to work with. When you want your agent to feel like a personal assistant in your pocket, Telegram is the right choice.
Discord excels at parallel, multi-context work. Each Discord channel provides a separate conversation context, which means you can have your agent working on different tasks in different channels simultaneously — research in one channel, code review in another, email drafting in a third. This channel-based separation is uniquely powerful for agent orchestration.
Setting Up a Telegram Bot
Telegram bots are created through BotFather, Telegram's official bot management tool.
Step 1: Create the bot
- Open Telegram and search for
@BotFather - Send the command
/newbot - Choose a display name (e.g., "My AI Agent")
- Choose a username ending in
bot(e.g.,my_ai_agent_bot) - BotFather responds with your bot token — save this securely
Step 2: Configure the bot in OpenClaw
# In your OpenClaw configuration
channels:
telegram:
bot_token: ${TELEGRAM_BOT_TOKEN}
allowed_users:
- "your_telegram_user_id"
# Set the token as an environment variable
export TELEGRAM_BOT_TOKEN="your-bot-token-here"
Step 3: Set bot commands (optional but recommended)
Send these to BotFather to define your bot's command menu:
/setcommands
status - Check agent status
help - Show available commands
task - Assign a new task
Step 4: Get your user ID
To restrict your bot to only respond to you, you need your Telegram user ID. Send a message to @userinfobot on Telegram — it will reply with your numeric user ID.
Setting Up a Discord Bot
Discord bots require a few more steps because of Discord's permission and intent system.
Step 1: Create a Discord application
- Go to the Discord Developer Portal (discord.com/developers/applications)
- Click "New Application" and give it a name
- Navigate to the "Bot" section and click "Add Bot"
- Copy the bot token — save this securely
- Under "Privileged Gateway Intents," enable Message Content Intent (required for reading messages)
Step 2: Invite the bot to your server
- In the Developer Portal, go to "OAuth2" then "URL Generator"
- Select scopes:
bot,applications.commands - Select permissions:
Send Messages,Read Message History,Embed Links,Attach Files - Copy the generated URL and open it in your browser to invite the bot
Step 3: Configure in OpenClaw
# In your OpenClaw configuration
channels:
discord:
bot_token: ${DISCORD_BOT_TOKEN}
allowed_guilds:
- "your_server_id"
allowed_roles:
- "agent-operator"
# Set the token as an environment variable
export DISCORD_BOT_TOKEN="your-discord-bot-token-here"
Discord's Parallel Context Advantage
This is where Discord becomes particularly valuable for agent work. Consider this setup:
| Channel | Purpose | Agent Behavior |
|---|---|---|
#research |
Web research tasks | Agent searches, summarizes, and saves findings |
#code-review |
Code analysis | Agent reviews PRs and provides feedback |
#email-drafts |
Email composition | Agent drafts emails for your review |
#daily-briefing |
Morning reports | Agent posts daily summaries on schedule |
#logs |
Agent activity logs | Agent logs all actions for audit |
Each channel maintains its own conversation context. When you message the agent in #research, it does not confuse that with the conversation happening in #code-review. This natural isolation means you can run multiple workflows in parallel without context pollution.
You can set this up by creating channels in your Discord server and configuring the agent to monitor specific channels:
channels:
discord:
bot_token: ${DISCORD_BOT_TOKEN}
monitored_channels:
- name: "research"
purpose: "Web research and summarization"
- name: "code-review"
purpose: "Code analysis and review"
- name: "email-drafts"
purpose: "Email composition and review"
Security Considerations
Messaging channels are a direct interface to your agent's capabilities. Securing them is critical.
Allow lists: Always restrict your bot to known users (Telegram) or specific servers and roles (Discord). An unrestricted bot is a security liability — anyone who finds it can issue commands.
Message validation: Validate incoming messages before processing. Check that the sender is authorized, the message format is expected, and the requested action is within allowed boundaries.
Token security: Bot tokens are equivalent to passwords. Never commit them to version control. Use environment variables or a secrets manager.
# WRONG: Token hardcoded in config
bot_token: "7234567890:AAF..."
# RIGHT: Token loaded from environment
bot_token: ${TELEGRAM_BOT_TOKEN}
Rate limiting: Implement rate limits to prevent accidental or malicious message floods from triggering excessive API calls and running up costs.
Audit logging: Log all commands received and actions taken. If something goes wrong, you need a clear trail of what happened and who triggered it.
Key takeaway: Telegram gives you a personal assistant in your pocket. Discord gives you a multi-channel command center. Use Telegram for direct interaction and Discord for parallel workflows — and always secure both with allow lists and proper token management.
Next: Expanding your agent's capabilities with memory, voice, and email integration. :::