Initial commit

This commit is contained in:
Zhongwei Li
2025-11-30 08:43:40 +08:00
commit d6cdda3f30
13 changed files with 4664 additions and 0 deletions

View File

@@ -0,0 +1,564 @@
---
name: discord-integration
version: 1.0.1
description: Use when sending Discord messages or encountering bot permission errors - provides three-tier integration methods with automatic fallback (MCP → REST API → Gateway); prevents wasted time on OAuth scope issues
triggers:
- discord
- send message
- permission error
- bot access
- discord.js
- mcp discord
---
# Discord Integration
Comprehensive skill for working with Discord from Claude Code using multiple methods with automatic fallback.
## When to Use This Skill
Use this skill when the user wants to:
- Send messages to Discord channels
- Read messages from Discord channels
- Troubleshoot Discord bot connection or permission issues
- Set up or configure Discord bot access
- Choose the best method for Discord interaction
**Trigger phrases:**
- "Send a message to Discord"
- "Post to #channel-name"
- "Read messages from Discord"
- "Discord bot isn't working"
- "Can't access Discord channel"
## When NOT to Use This Skill
**Do NOT use this skill for:**
- **Discord server management** - Use Discord's admin panel for creating channels, managing roles, or configuring server settings
- **Complex bot features** - For advanced slash commands, persistent state, or complex workflows, build a dedicated bot application
- **Real-time message listening** - This skill focuses on sending/reading; continuous message monitoring requires a persistent Gateway connection outside this skill's scope
- **Voice channel interactions** - This skill only handles text channels
## Available Bots on This Machine
### 1. Sombra (Local MCP Bot)
- **Purpose:** Claude Code MCP integration (this machine only)
- **Token Location:** `~/.claude/discordmcp/.env`
- **Client ID:** 1435274653126889544
- **Guild:** Nice Wolf Studio (745376918030909471)
- **Connection:** discord.js Gateway via MCP server
- **Use For:** Claude Code sessions, automated workflows
### 2. GladOSv3 (tjr-suite Bot)
- **Purpose:** Trading bot application
- **Token Location:** `~/Dev/tjr-suite/.env`
- **Client ID:** 1425850836277395506
- **Guild:** Nice Wolf Studio (745376918030909471)
- **Connection:** discord.js Gateway (always running)
- **Use For:** Trading signals, slash commands, application-specific tasks
**Important:** These are separate bots. Do not confuse their configurations.
## Three Integration Methods (Priority Order)
### Method 1: MCP Tools (PREFERRED)
**Availability:** After Claude Code full restart
**Tools:** `mcp__discord__send-message`, `mcp__discord__read-messages`
**Pros:**
- Clean, native Claude Code integration
- No manual script execution
- Persistent connection via discord.js Gateway
- Smart auto-discovery (find channels by name or ID)
**Cons:**
- Requires full Claude Code restart to load
- Not available immediately after config changes
### Method 2: Discord.js Gateway Script (FALLBACK)
**Availability:** Always (if bot token configured)
**Script:** `~/.claude/discordmcp/send-test-message.js`
**Pros:**
- Works immediately, no restart needed
- Direct access to discord.js library
- Can be customized easily
- Reliable connection
**Cons:**
- Requires manual script execution
- Less integrated than MCP tools
### Method 3: REST API (LAST RESORT)
**Availability:** Always
**Method:** Direct curl to Discord API v10
**Pros:**
- No dependencies
- Quick for testing
**Cons:**
- Often gets "Missing Access" (OAuth scope issues)
- Requires exact permissions
- Less reliable than Gateway methods
## Integration Method Selection (MANDATORY)
**ALWAYS follow this priority order - do NOT skip steps:**
```
User requests Discord interaction
STEP 1: Are MCP tools available? (mcp__discord__send-message)
YES → REQUIRED: Use MCP tools (Method 1)
NO ↓
STEP 2: Can we use send-test-message.js? (file exists, token configured)
YES → REQUIRED: Use Gateway script (Method 2)
NO ↓
STEP 3: Try REST API (Method 3) with warning about limitations
FALLBACK LOGIC:
- If Method 1 fails → Immediately try Method 2
- If Method 2 fails → Try Method 3
- If Method 3 fails → Report error with troubleshooting steps
```
**CRITICAL:** You MUST attempt Method 1 (MCP) first, even if you think it won't work. Only fall back after confirming failure.
## Step-by-Step Instructions
### Step 1: Check Method Availability
**Before attempting any Discord interaction, determine which method is available:**
1. **Try MCP tools first:**
```javascript
// Attempt to use MCP tool
mcp__discord__send-message({
channel: "CHANNEL_ID",
message: "Test"
})
```
If you get "No such tool available" error → MCP not loaded
2. **Fall back to Gateway script:**
```bash
# Check if script exists
ls -la ~/.claude/discordmcp/send-test-message.js
# Check if token configured
grep DISCORD_TOKEN ~/.claude/discordmcp/.env
```
3. **REST API as last resort** (expect permission issues)
### Step 2: Execute Based on Available Method
#### Using Method 1: MCP Tools
**Send Message:**
```javascript
mcp__discord__send-message({
channel: "1420759585349697710", // Channel ID or name
message: "Your message here"
})
```
**Read Messages:**
```javascript
mcp__discord__read-messages({
channel: "1420759585349697710",
limit: 10 // 1-100
})
```
#### Using Method 2: Gateway Script
**Send Message:**
```bash
cd ~/.claude/discordmcp
node send-test-message.js CHANNEL_ID "Optional custom message"
# Example:
node send-test-message.js 1420759585349697710 "Hello from Claude Code"
```
**Custom Message:**
Create a modified version of the script or pass message as argument.
#### Using Method 3: REST API
**Send Message:**
```bash
curl -X POST "https://discord.com/api/v10/channels/CHANNEL_ID/messages" \
-H "Authorization: Bot ${DISCORD_BOT_TOKEN}" \
-H "Content-Type: application/json" \
-d '{"content": "Your message"}'
```
**Note:** Will likely fail with "Missing Access" - see troubleshooting.
### Step 3: Handle Errors
See troubleshooting section below for specific error codes and solutions.
## Red Flags - STOP
**If you encounter these situations, STOP and address them immediately:**
❌ **Skipping MCP method without trying first**
- **Why it's bad:** MCP is the most reliable method; skipping wastes time with inferior fallbacks
- **Fix:** Always attempt `mcp__discord__send-message` before assuming it won't work
❌ **Not checking bot permissions before sending**
- **Why it's bad:** Results in repeated "Missing Access" errors and wasted API calls
- **Fix:** Verify bot has "View Channel" and "Send Messages" permissions first
❌ **Retrying same failed method repeatedly**
- **Why it's bad:** Same input = same output; you're wasting time and rate limits
- **Fix:** After one failure, switch to next method in priority order
❌ **Missing token/credentials setup**
- **Why it's bad:** Nothing will work without valid authentication
- **Fix:** Verify token exists in appropriate .env file and test with `/users/@me` endpoint
❌ **Not handling 403 Forbidden errors properly**
- **Why it's bad:** 403 means permission issue, not connection issue
- **Fix:** Check channel-specific permissions or switch to Gateway method (better permission handling)
❌ **Using REST API when Gateway methods are available**
- **Why it's bad:** REST API has OAuth scope limitations that cause "Missing Access" errors
- **Fix:** Use MCP tools or Gateway script instead - they have proper intents
## Verification Checklist
**Before marking Discord integration as complete, verify:**
- [ ] **MCP tools attempted first** - You tried `mcp__discord__send-message` before other methods
- [ ] **Permissions verified for channel** - Bot has "View Channel" and "Send Messages" in target channel
- [ ] **Message sent successfully** - Received confirmation (not just "no error")
- [ ] **Error handling implemented** - Code handles failures gracefully with fallback or clear error message
- [ ] **Correct bot used** - Sombra for MCP/local, GladOSv3 for tjr-suite (not mixed up)
- [ ] **Token validated** - Tested token with `/users/@me` endpoint returns valid bot info
## Prerequisites
### General Requirements
- Bot must be in the target Discord server
- Bot must have proper permissions in the target channel
- Valid bot token must be configured
### For MCP Tools
- Claude Code must be fully restarted after mcp.json changes
- MCP server must be configured in `~/.claude/mcp.json`
- Discord MCP server must be built: `cd ~/.claude/discordmcp && npm run build`
### For Gateway Script
- Node.js installed
- discord.js package available (in discordmcp directory)
- Token in `~/.claude/discordmcp/.env`
### For REST API
- `DISCORD_BOT_TOKEN` environment variable set
- Bot must have been added with proper OAuth2 scopes
## Troubleshooting
### Error: "No such tool available: mcp__discord__send-message"
**Cause:** Discord MCP server not loaded in Claude Code.
**Solutions:**
1. **Verify MCP configuration exists:**
```bash
grep -A 5 '"discord"' ~/.claude/mcp.json
```
Should show:
```json
"discord": {
"type": "stdio",
"command": "node",
"args": ["/Users/USERNAME/.claude/discordmcp/build/index.js"]
}
```
2. **Verify MCP server is built:**
```bash
ls -la ~/.claude/discordmcp/build/index.js
```
3. **Test MCP server manually:**
```bash
cd ~/.claude/discordmcp
node build/index.js
```
Should see: "Discord bot is ready!" and "Discord MCP Server running on stdio"
4. **Fully restart Claude Code:**
- Quit completely (Cmd+Q or equivalent)
- Relaunch application
- Start new session
5. **If still not available, use Method 2 (Gateway script) instead.**
### Error: "Missing Access" (Code 50001)
**Cause:** Bot doesn't have permission to access that channel.
**Solutions:**
1. **Verify bot is in the server:**
```bash
curl -H "Authorization: Bot TOKEN" \
https://discord.com/api/v10/users/@me/guilds
```
2. **Check channel-specific permissions:**
- Right-click channel in Discord
- Edit Channel → Permissions
- Add the bot (Sombra or GladOSv3)
- Enable: View Channel, Send Messages, Read Message History
3. **Grant server-wide permissions:**
- Server Settings → Roles
- Find bot's role
- Enable Send Messages permission
4. **If using REST API, switch to Gateway method** (discord.js or MCP tools)
### Error: "Unknown Guild" (Code 10004)
**Cause:** Bot is not in that Discord server.
**Solutions:**
1. **Verify bot membership:**
```bash
curl -H "Authorization: Bot TOKEN" \
https://discord.com/api/v10/users/@me/guilds
```
2. **Invite bot to server using OAuth2 URL:**
**For Sombra (Local MCP):**
```
https://discord.com/api/oauth2/authorize?client_id=1435274653126889544&permissions=69632&scope=bot
```
**For GladOSv3 (tjr-suite):**
```
https://discord.com/api/oauth2/authorize?client_id=1425850836277395506&permissions=69632&scope=bot
```
3. **After inviting, wait a few seconds for bot to join**
4. **Verify the bot appears in server member list**
### Error: Connection Timeout or "Discord bot is ready!" but MCP fails
**Cause:** Token invalid or bot permissions insufficient.
**Solutions:**
1. **Verify token is correct:**
```bash
curl -H "Authorization: Bot TOKEN" \
https://discord.com/api/v10/users/@me
```
Should return bot user info, not error.
2. **Check token hasn't been regenerated:**
- Go to Discord Developer Portal
- Applications → Your Bot → Bot
- If token was regenerated, update configs
3. **Verify bot has proper Gateway intents:**
- In Developer Portal: Bot → Privileged Gateway Intents
- Enable: Guilds, Guild Messages (Message Content if reading)
4. **Check .env file syntax:**
```bash
cat ~/.claude/discordmcp/.env
```
No extra spaces, quotes, or newlines around token.
### Error: "Channel not found or not a text channel"
**Cause:** Invalid channel ID or bot can't see it.
**Solutions:**
1. **Verify channel ID is correct:**
- Right-click channel in Discord
- Copy Channel ID (enable Developer Mode if needed)
- Channel IDs are 17-19 digit numbers
2. **Check bot can see the channel:**
- Bot must have "View Channel" permission
- Channel must not be in a category the bot can't access
3. **Try using channel name instead of ID** (if using MCP tools):
```javascript
mcp__discord__send-message({
channel: "bot-testing-grounds", // Name instead of ID
message: "Test"
})
```
## Bot Configuration Reference
### Sombra (Local MCP) Configuration
**Files:**
- **Token:** `~/.claude/discordmcp/.env`
- **MCP Config:** `~/.claude/mcp.json` (lines 55-61)
- **Source:** `~/.claude/discordmcp/src/index.ts`
- **Built:** `~/.claude/discordmcp/build/index.js`
**Environment Variables:**
```env
DISCORD_TOKEN=MTQzNTI3NDY1MzEyNjg4OTU0NA...
DISCORD_CLIENT_ID=1435274653126889544
DISCORD_GUILD_ID=745376918030909471
DISCORD_ENABLED=true
```
**Rebuild after changes:**
```bash
cd ~/.claude/discordmcp
npm run build
```
### GladOSv3 (tjr-suite) Configuration
**Files:**
- **Token:** `~/Dev/tjr-suite/.env`
- **Source:** `~/Dev/tjr-suite/packages/app/src/services/discord/`
- **HTTP API:** Running on `http://localhost:3000`
**Environment Variables:**
```env
DISCORD_TOKEN=MTQyNTg1MDgzNjI3NzM5NTUwNg...
DISCORD_CLIENT_ID=1425850836277395506
DISCORD_GUILD_ID=745376918030909471
DISCORD_ENABLED=true
```
**Note:** GladOSv3 is always running as part of tjr-suite. Do not confuse with Sombra.
## Common Channel IDs
**Nice Wolf Studio Server:**
- **Guild ID:** 745376918030909471
- **#bot-testing-grounds:** 1420759585349697710
## Permission Reference
### Required Bot Permissions
**Minimum (for message sending):**
- View Channels (1024)
- Send Messages (2048)
**Recommended:**
- Read Message History (65536)
- Add Reactions (64)
**Permission Integer:** 69632 (includes all recommended)
### How to Calculate Custom Permissions
Visit: https://discordapi.com/permissions.html
Enter desired permissions, copy the integer for OAuth2 URL.
## Testing Checklist
When setting up or troubleshooting Discord integration:
- [ ] Bot token is valid (test with `/users/@me` endpoint)
- [ ] Bot is in the correct server (check `/users/@me/guilds`)
- [ ] Bot has View Channel permission
- [ ] Bot has Send Messages permission in target channel
- [ ] Channel ID is correct (17-19 digit number)
- [ ] Token configured in correct .env file
- [ ] MCP server built (if using MCP tools)
- [ ] Claude Code restarted (if using MCP tools)
## Quick Reference Commands
### Verify Token
```bash
curl -H "Authorization: Bot TOKEN" https://discord.com/api/v10/users/@me
```
### List Guilds
```bash
curl -H "Authorization: Bot TOKEN" https://discord.com/api/v10/users/@me/guilds
```
### Test MCP Server
```bash
cd ~/.claude/discordmcp && node build/index.js
```
### Send via Gateway Script
```bash
cd ~/.claude/discordmcp && node send-test-message.js CHANNEL_ID "Message"
```
### Check MCP Config
```bash
grep -A 5 '"discord"' ~/.claude/mcp.json
```
## Examples
See `examples.md` in this skill directory for complete working examples.
## Related Documentation
- **Setup Guide:** `~/.claude/discordmcp/SETUP_COMPLETE.md`
- **Validation Report:** `~/.claude/discordmcp/VALIDATION_REPORT.md`
- **Gateway Script:** `~/.claude/discordmcp/send-test-message.js`
- **Discord.js Docs:** https://discord.js.org/
- **Discord API:** https://discord.com/developers/docs
---
## After Using This Skill
**REQUIRED NEXT STEPS:**
1. **Verify message sent successfully** - Check verification checklist (6 items) to confirm integration worked
2. **Document method used** - Record which method succeeded (MCP/Gateway/REST) for future reference
3. **Test error handling** - Verify fallback logic works if primary method fails
**OPTIONAL NEXT STEPS:**
- **Set up logging** - Track Discord API calls, errors, and response times for debugging
- **Create reusable wrapper** - Build abstraction around working method for consistent usage
- **Monitor bot health** - Set up alerts for token expiration or permission changes
---
## Changelog
### Version 1.0.1 (2025-11-14)
- **Added** superpowers-style improvements for better agent guidance
- **Added** "When NOT to Use" section to prevent misuse
- **Enhanced** Integration Method Selection with MANDATORY fallback logic
- **Added** "Red Flags - STOP" section with 6 common anti-patterns
- **Added** "Verification Checklist" for completion validation
- **Improved** frontmatter with version, triggers, and clearer description
- **Updated** description to emphasize automatic fallback and OAuth scope issue prevention
### Version 1.0.0 (Initial)
- Initial discord-integration skill
- Three-tier integration methods (MCP, Gateway, REST API)
- Comprehensive troubleshooting for common errors
- Configuration reference for Sombra and GladOSv3 bots

View File

@@ -0,0 +1,517 @@
# Discord Integration - Examples
Complete working examples for all three integration methods.
## Method 1: MCP Tools (After Claude Code Restart)
### Example 1: Send Simple Message
**User Request:**
> Send a message to Discord channel 1420759585349697710 saying "Test from Claude Code"
**Assistant Response:**
```javascript
mcp__discord__send-message({
channel: "1420759585349697710",
message: "Test from Claude Code"
})
```
**Expected Result:**
```
Message sent successfully to #bot-testing-grounds in Nice Wolf Studio. Message ID: 1234567890123456789
```
---
### Example 2: Send Formatted Message
**User Request:**
> Post a formatted update to the bot-testing-grounds channel
**Assistant Response:**
```javascript
mcp__discord__send-message({
channel: "1420759585349697710",
message: `🤖 **Status Update**
✅ System: Online
✅ Database: Connected
✅ API: Healthy
Last checked: ${new Date().toISOString()}`
})
```
---
### Example 3: Read Recent Messages
**User Request:**
> What are the last 10 messages in #bot-testing-grounds?
**Assistant Response:**
```javascript
mcp__discord__read-messages({
channel: "1420759585349697710",
limit: 10
})
```
**Expected Result:**
```json
[
{
"channel": "#bot-testing-grounds",
"server": "Nice Wolf Studio",
"author": "Sombra#2394",
"content": "Test message",
"timestamp": "2025-11-04T14:43:09.073Z"
},
...
]
```
---
### Example 4: Using Channel Name (Auto-Discovery)
**User Request:**
> Send "Hello" to the general channel
**Assistant Response:**
```javascript
mcp__discord__send-message({
channel: "general", // Channel name instead of ID
message: "Hello"
})
```
**Note:** MCP server will auto-discover channel by name if bot is only in one server.
---
## Method 2: Gateway Script (Always Available)
### Example 5: Send Message via Script
**User Request:**
> Send a message to Discord right now
**Assistant Response (if MCP not available):**
```bash
cd ~/.claude/discordmcp
node send-test-message.js 1420759585349697710 "Message sent via Gateway script"
```
**Expected Output:**
```
🔌 Connecting to Discord...
✅ Connected to Discord
📡 Bot: Sombra#2394
🏠 Guilds: 1
✅ Found guild: Nice Wolf Studio
✅ Found channel: #bot-testing-grounds
📤 Sending message...
✅ Message sent! ID: 1435281072207171654
👋 Disconnected
```
---
### Example 6: Send Multi-Line Message
**User Request:**
> Post a detailed status report to Discord
**Assistant Response:**
```bash
cd ~/.claude/discordmcp
node send-test-message.js 1420759585349697710 "📊 **Daily Report**
✅ Tasks completed: 15
⏳ In progress: 3
🔴 Blocked: 1
Next update in 24 hours."
```
---
### Example 7: Create Custom Script for Specific Need
**User Request:**
> I need to send messages to multiple channels
**Assistant Response:**
I'll create a custom multi-channel script based on send-test-message.js:
```javascript
// save as: ~/.claude/discordmcp/multi-channel-send.js
import { Client, GatewayIntentBits } from 'discord.js';
import { config } from 'dotenv';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
config({ path: join(__dirname, '.env') });
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
});
async function sendToMultiple() {
await client.login(process.env.DISCORD_TOKEN);
await new Promise((resolve) => client.once('ready', resolve));
const channels = [
"1420759585349697710", // bot-testing-grounds
"ANOTHER_CHANNEL_ID",
];
const message = process.argv[2] || "Multi-channel broadcast";
for (const channelId of channels) {
const channel = await client.channels.fetch(channelId);
if (channel && 'send' in channel) {
await channel.send(message);
console.log(`✅ Sent to ${channel.name}`);
}
}
await client.destroy();
}
sendToMultiple().catch(console.error);
```
**Usage:**
```bash
cd ~/.claude/discordmcp
node multi-channel-send.js "Broadcast message"
```
---
## Method 3: REST API (Last Resort)
### Example 8: Simple REST API Test
**User Request:**
> Test if the bot token works
**Assistant Response:**
```bash
# Get bot info
curl -H "Authorization: Bot ${DISCORD_BOT_TOKEN}" \
https://discord.com/api/v10/users/@me | python3 -m json.tool
```
**Expected Output:**
```json
{
"id": "1435274653126889544",
"username": "Sombra",
"bot": true,
"verified": true
}
```
---
### Example 9: Check Bot's Guilds
**User Request:**
> Which servers is the bot in?
**Assistant Response:**
```bash
curl -H "Authorization: Bot ${DISCORD_BOT_TOKEN}" \
https://discord.com/api/v10/users/@me/guilds | python3 -m json.tool
```
---
### Example 10: Try Sending via REST (Expect Failure)
**User Request:**
> Try sending via REST API
**Assistant Response:**
```bash
curl -X POST "https://discord.com/api/v10/channels/1420759585349697710/messages" \
-H "Authorization: Bot ${DISCORD_BOT_TOKEN}" \
-H "Content-Type: application/json" \
-d '{"content": "Test from REST API"}'
```
**Likely Error:**
```json
{"message": "Missing Access", "code": 50001}
```
**Explanation:** REST API often fails due to OAuth scope issues. Use Gateway method (Method 2) instead.
---
## Troubleshooting Examples
### Example 11: MCP Tools Not Available
**User Request:**
> Send a message to Discord
**Assistant Attempt:**
```javascript
mcp__discord__send-message({
channel: "1420759585349697710",
message: "Test"
})
```
**Error:**
```
Error: No such tool available: mcp__discord__send-message
```
**Assistant Recovery:**
The Discord MCP tools aren't loaded yet. Let me use the Gateway script instead:
```bash
cd ~/.claude/discordmcp
node send-test-message.js 1420759585349697710 "Test"
```
**Success:**
```
✅ Message sent! ID: 1435281072207171654
```
**Explanation to User:**
> The MCP tools require a full Claude Code restart to load. I've used the Gateway script method instead, which works immediately. If you want to use MCP tools in the future, quit and relaunch Claude Code.
---
### Example 12: Missing Channel Permissions
**User Request:**
> Send to channel 9999999999999999999
**Assistant Attempt:**
```bash
node send-test-message.js 9999999999999999999 "Test"
```
**Error:**
```
❌ Error: Missing Access
DiscordAPIError[50001]: Missing Access
```
**Assistant Response:**
The bot doesn't have permission to access that channel. Let me help you fix this:
1. **Verify the channel ID is correct:**
```
Right-click the channel in Discord → Copy Channel ID
```
2. **Grant bot permissions:**
- Right-click the channel → Edit Channel
- Permissions → Add "Sombra" bot
- Enable: View Channel, Send Messages
3. **Try again after granting permissions**
---
### Example 13: Bot Not in Server
**User Request:**
> Send to my private server
**Assistant Check:**
```bash
curl -H "Authorization: Bot ${DISCORD_BOT_TOKEN}" \
https://discord.com/api/v10/users/@me/guilds
```
**Response:**
```json
[
{
"id": "745376918030909471",
"name": "Nice Wolf Studio"
}
]
```
**Assistant Response:**
The bot is only in "Nice Wolf Studio" server currently. To add it to your private server:
**For Sombra (Local MCP):**
```
https://discord.com/api/oauth2/authorize?client_id=1435274653126889544&permissions=69632&scope=bot
```
After inviting the bot, you can send messages to channels in that server.
---
## Complete Workflow Examples
### Example 14: First-Time Setup Verification
**User Request:**
> Make sure Discord integration is working
**Assistant Workflow:**
**Step 1: Test token**
```bash
curl -H "Authorization: Bot $(grep DISCORD_TOKEN ~/.claude/discordmcp/.env | cut -d= -f2)" \
https://discord.com/api/v10/users/@me
```
**Step 2: Check guilds**
```bash
curl -H "Authorization: Bot $(grep DISCORD_TOKEN ~/.claude/discordmcp/.env | cut -d= -f2)" \
https://discord.com/api/v10/users/@me/guilds
```
**Step 3: Test MCP server**
```bash
cd ~/.claude/discordmcp && node build/index.js &
sleep 3
pkill -f "node build/index.js"
```
**Step 4: Send test message**
```bash
cd ~/.claude/discordmcp
node send-test-message.js 1420759585349697710 "✅ Discord integration test successful"
```
**Report:**
> ✅ All checks passed! Discord integration is working correctly.
> - Bot: Sombra#2394
> - Server: Nice Wolf Studio
> - Test message sent successfully
>
> MCP tools will be available after a full Claude Code restart.
---
### Example 15: Switching Between Bots
**User Request:**
> Use the tjr-suite bot instead of Sombra
**Assistant Response:**
Currently, Sombra (Local MCP) is configured for Claude Code. GladOSv3 (tjr-suite bot) is running separately in the tjr-suite application.
**To use GladOSv3 from Claude Code:**
1. **Update MCP config to use tjr-suite token:**
```bash
# Edit ~/.claude/discordmcp/.env
DISCORD_TOKEN=MTQyNTg1MDgzNjI3NzM5NTUwNg... # GladOSv3 token
DISCORD_CLIENT_ID=1425850836277395506
```
2. **Rebuild and restart:**
```bash
cd ~/.claude/discordmcp
npm run build
```
3. **Restart Claude Code**
**Or, keep them separate:**
- Use Sombra for Claude Code (current setup)
- Use GladOSv3 for tjr-suite app (via slash commands in Discord)
---
## Best Practices from Experience
### Always Use Gateway Methods When Possible
**❌ Don't:**
```bash
# REST API (often fails)
curl -X POST "..." -H "Authorization: Bot $TOKEN" ...
```
**✅ Do:**
```bash
# Gateway script (reliable)
cd ~/.claude/discordmcp && node send-test-message.js CHANNEL_ID "Message"
```
**Or even better:**
```javascript
// MCP tools (after restart)
mcp__discord__send-message({ channel: "...", message: "..." })
```
---
### Check Method Availability First
**✅ Good Pattern:**
```
1. Try MCP tool
2. If not available, use Gateway script
3. Explain REST limitations if asked
```
**❌ Bad Pattern:**
```
1. Jump straight to REST API
2. Get "Missing Access" error
3. Struggle with permissions
```
---
### Provide Context in Error Messages
**❌ Don't:**
```
Error: Missing Access
[end response]
```
**✅ Do:**
```
Error: Missing Access
This means the bot doesn't have permission to access that channel.
To fix:
1. Right-click the channel → Edit Channel
2. Permissions → Add "Sombra"
3. Enable: View Channel, Send Messages
Alternatively, I can use a different method...
```
---
## Summary: When to Use Each Method
| Scenario | Use Method |
|----------|------------|
| MCP tools available | Method 1 (MCP) |
| MCP tools not loaded | Method 2 (Gateway script) |
| Need immediate result | Method 2 (Gateway script) |
| Testing token validity | Method 3 (REST API) |
| Checking bot guilds | Method 3 (REST API) |
| Actually sending messages | Method 1 or 2 (NOT REST) |
| Custom workflows | Method 2 (customize script) |
| Multiple channels | Method 2 (custom script) |
**Golden Rule:** Gateway > REST for actual message operations.