Build An Interactive Discord Bot
Build An Interactive Discord BotThis guide will walk you through setting up and using the Skillful AI Discord bot integration. Our Discord integration allows you to create AI-powered Discord bots that can interact with users, generate images, and leverage all of Skillful AI's capabilities.
Step 1: Prerequisites
Step 1: PrerequisitesDiscord Bot Setup
Go to Discord Developer Portal
Click "New Application"
Navigate to the "Bot" section
Click "Add Bot"
Enable Privileged Intents:
MESSAGE CONTENT INTENT
SERVER MEMBERS INTENT
PRESENCE INTENT
Copy your bot token
Skillful AI Setup
Reach out for an API key
Step 2: Installation
Step 2: InstallationUsing a code editor like Visual Studio Code, we can create a new project with:
# Create new project directory
mkdir my-skillful-bot
cd my-skillful-bot
# Initialize our project
npm init -y
# Install the Discord bot template
npm install @skillfulai/discord-templateStep 3: Basic Setup
Step 3: Basic SetupCreate an index.js script and copy the below into it. The basic setup will disable ProActive Mode by default, but enable everything else you need to interact with your AI Agent.
const SkillfulDiscordBot = require('@skillfulai/discord-template');
// Initialize bot
const bot = new SkillfulDiscordBot({
discordToken: 'your_discord_token',
skillfulApiKey: 'your_skillful_api_key'
// Optional
agentName: 'Wojak', // Your Agent Name
debug: false, // Default: false
proactive: false, // Default: false
proactiveThreshold: 50 // Default: 50
});
// Start bot
bot.start()
.then(() => console.log('Bot started'))
.catch(console.error);
// Handle shutdown
process.on('SIGINT', async () => {
await bot.stop();
process.exit(0);
});Step 4: Run the Bot
Step 4: Run the BotRun your bot to start the application:
node index.jsBasic Usage
Basic UsageYou can interact with your agent in a few different ways:
Direct Mentions
The bot responds to direct mentions:
@YourBot Hello there!Replies
The bot will respond to direct replies.
ProActive Mode
If ProActive Mode has been enabled in the constructor, your bot will dynamically jump into conversations and reply to users.
Debug Mode
Debug ModeEnable debug logging:
const bot = new SkillfulDiscordBot({
discordToken: 'token',
skillfulApiKey: 'key',
debug: true
});Debug mode shows:
Message processing
Engagement decisions
Error details
Connection status
Error Handling
Error Handlingbot.start()
.then(() => console.log('Bot started'))
.catch(error => {
console.error('Startup error:', error);
process.exit(1);
});Best Practices
Best PracticesEnvironment Variables
require('dotenv').config(); const bot = new SkillfulDiscordBot({ discordToken: process.env.DISCORD_TOKEN, skillfulApiKey: process.env.SKILLFUL_API_KEY });Proper Shutdown
process.on('SIGINT', async () => { console.log('Shutting down...'); await bot.stop(); process.exit(0); });Error Monitoring
process.on('unhandledRejection', error => { console.error('Unhandled promise rejection:', error); });
Troubleshooting
TroubleshootingCommon Issues
Invalid Token
Verify token in Discord Developer Portal
Check for token format issues
Ensure intents are enabled
Connection Issues
Check internet connection
Verify Discord API status
Check for rate limiting
Permission Issues
Verify bot has required permissions
Check channel permissions
Verify intent settings
For more help, join our Discord community.
Last updated