All posts
tutorial|10 min read

Building a Discord Bot with Moltbot

Learn how to create a smart Discord bot powered by Moltbot's AI capabilities.

M

Molty Team

Molty by Finna

ShareX

Discord has grown from a gaming chat app into a platform where communities of all kinds gather. Whether you run a developer community, a study group, a customer support server, or a hobbyist club, adding an AI-powered bot can transform how your server operates. This guide walks you through building a Discord bot with Moltbot, managed through the Molty by Finna platform.

What Makes Discord Bots Different

Discord bots operate in a fundamentally different environment from bots on platforms like WhatsApp or Telegram. Understanding these differences will help you build a better bot:

  • Server-based - Discord bots live in servers (communities), not just individual chats
  • Channel-aware - Bots can be configured to work in specific channels
  • Role-based permissions - Discord's permission system controls what bots can see and do
  • Rich interactions - Embeds, buttons, reactions, threads, and more
  • Multiple concurrent conversations - Your bot might be active in dozens of channels simultaneously

Moltbot handles all of this complexity behind the scenes, but knowing the landscape helps you configure things properly.

Step 1: Create a Discord Application

Everything starts at the Discord Developer Portal.

  1. Go to discord.com/developers/applications and sign in.
  2. Click "New Application" in the top right.
  3. Give your application a name. This will be the default name for your bot, though you can change it later.
  4. Accept the terms of service and click "Create."

You are now in the application settings. Take a moment to fill in the description and upload an app icon - these show up when people look at your bot's profile.

Step 2: Create the Bot User

Within your application, you need to create the actual bot user.

  1. Navigate to the "Bot" section in the left sidebar.
  2. You will see your bot has been automatically created with the application.
  3. Click "Reset Token" to generate a new bot token.
  4. Copy the token immediately - Discord will only show it once.

Critical: Store this token securely. Never commit it to version control, share it in chat, or include it in screenshots. If the token is compromised, anyone can impersonate your bot.

Configure Intents

While in the Bot settings, scroll down to "Privileged Gateway Intents." These control what data your bot can access:

  • Presence Intent - See when users are online/offline. Not needed for most AI bots.
  • Server Members Intent - Access member lists. Enable if your bot needs to know about server members.
  • Message Content Intent - Read message content. You must enable this for Moltbot to process messages.

Toggle on "Message Content Intent" at minimum. Without it, your bot will receive events but will not be able to read what users write.

Step 3: Invite the Bot to Your Server

Before connecting to Moltbot, add the bot to your Discord server.

  1. Go to the "OAuth2" section, then "URL Generator."
  2. Under "Scopes," select bot.
  3. Under "Bot Permissions," select the permissions your bot needs. At minimum:
    • Read Messages/View Channels
    • Send Messages
    • Embed Links (for rich formatting)
    • Read Message History
    • Add Reactions (optional but useful)
    • Use Slash Commands (if you want command support)
  4. Copy the generated URL at the bottom.
  5. Open the URL in your browser, select the server you want to add the bot to, and authorize it.

The bot will appear in your server's member list as offline. It will come online once you connect it to Moltbot.

Step 4: Set Up Your Molty Gateway

If you have not already created a gateway on Molty by Finna:

  1. Log in to your dashboard at finna.cloud.
  2. Click "Create Gateway" and give it a name.
  3. Pick a server region close to your user base.
  4. Wait about 60 seconds for provisioning.

Each gateway runs in a dedicated Fly.io virtual machine, which means your bot's data and processing are isolated from other users on the platform.

Step 5: Connect Discord to Your Gateway

With the gateway running:

  1. Open your gateway in the Molty dashboard.
  2. Go to the "Channels" tab.
  3. Enable the Discord channel.
  4. Paste your bot token into the configuration field.
  5. Save and apply the settings.

The bot should come online in your Discord server within a few seconds. The channel status in Molty will show "Connected."

Quick Test

Go to your Discord server and send a message in a channel the bot can see. Type something like "Hey bot, are you there?" If the bot responds with an AI-generated message, everything is working.

Configuring Channel Behavior

Discord servers typically have many channels, and you probably do not want your bot responding in all of them. Here is how to manage this.

Restricting to Specific Channels

The simplest approach is using Discord's built-in permissions:

  1. In your Discord server, go to Server Settings then Roles.
  2. Find your bot's role (created automatically when the bot joined).
  3. For channels where the bot should not respond, deny the "View Channel" or "Send Messages" permission for the bot's role.

This way, the bot only operates in channels where you have explicitly granted access.

Creating a Dedicated Bot Channel

Many servers create a specific channel for bot interactions:

  1. Create a new channel like #ask-ai or #bot-chat.
  2. Set permissions so the bot can read and send messages there.
  3. Optionally restrict the bot from other channels.
  4. Add a channel topic explaining how to use the bot.

This keeps AI conversations organized and prevents the bot from cluttering other discussions.

Group Conversations and Context

Discord channels are inherently group conversations, which creates interesting dynamics for an AI bot.

How Moltbot Handles Discord Messages

By default, Moltbot responds to messages that mention the bot (using @mention) or reply to one of the bot's messages. This prevents the bot from jumping into every conversation uninvited.

You can adjust this behavior in the Molty dashboard:

  • Mention mode - Only respond when @mentioned (recommended for busy servers)
  • Active mode - Respond to all messages in channels the bot can see (best for dedicated bot channels)
  • Reply mode - Only respond when someone replies to the bot's messages

Thread Support

Discord threads are a great way to have extended conversations without cluttering the main channel. When a user starts a thread from one of the bot's messages, Moltbot can continue the conversation within that thread, maintaining context throughout.

Slash Commands Compatibility

Discord has been moving toward slash commands as the primary way users interact with bots. While Moltbot primarily works through natural language, it integrates well with Discord's command system.

Registering Slash Commands

Slash commands are defined through the Discord API. For an AI assistant, you might want commands like:

  • /ask [question] - Ask the AI a question
  • /reset - Clear conversation context
  • /help - Show what the bot can do

You can register these through the Discord Developer Portal or let Moltbot handle them based on your configuration.

Natural Language vs Commands

The beauty of an AI-powered bot is that you do not strictly need slash commands. Users can simply @mention the bot and write in plain English. However, slash commands provide discoverability - new users can type / and see what the bot offers, which lowers the barrier to first interaction.

We recommend supporting both: slash commands for quick actions and natural language for everything else.

Moderation Features

AI bots can help with server moderation, though this requires careful configuration.

Content Monitoring

You can configure your bot's system prompt to flag potentially problematic content. For example: "If a user's message contains obvious spam, harassment, or harmful content, note this in your response and suggest the server moderators review it."

Automated Responses

For frequently asked questions or common server issues, the bot can provide instant answers without human moderator involvement. This is especially useful for:

  • Welcome messages for new members
  • Pointing users to the right channels
  • Answering FAQs about server rules or community guidelines
  • Providing resource links

What Bots Should Not Do

Be cautious about giving AI bots moderation power like banning or muting users. AI can misinterpret context, sarcasm, or inside jokes. Keep moderation actions in the hands of human moderators and use the bot as an assistant that surfaces information rather than takes action.

Performance and Scaling

Response Times

Discord users expect quick responses. Moltbot typically responds within 2 to 5 seconds, depending on the AI model and complexity of the question. For faster responses:

  • Use a lighter AI model for simple queries
  • Keep your system prompt concise
  • Minimize unnecessary tool invocations

Handling High Traffic

If your server is large and the bot receives many simultaneous messages, Moltbot queues and processes them in order. The dedicated VM ensures your bot's performance is not affected by other users on the Molty platform.

For very high-traffic servers (thousands of messages per day), consider upgrading to Molty's Team or Enterprise plan for additional processing capacity.

Best Practices for Discord AI Bots

Set Clear Expectations

Pin a message or create a channel topic explaining what the bot can and cannot do. Users who understand the bot's capabilities will have better interactions.

Use Embeds for Rich Responses

Moltbot formats responses appropriately for Discord, including code blocks, bold text, and structured layouts. For complex responses like search results or data summaries, the formatting makes a big difference in readability.

Respect the Community Culture

Every Discord server has its own culture and norms. Configure your bot's personality to match. A gaming server's bot should be casual and fun, while a professional community's bot should be more measured and precise.

Monitor and Iterate

Review how people interact with your bot regularly. Common patterns to look for:

  • Questions the bot struggles with (improve your system prompt)
  • Features users ask for (consider enabling more tools)
  • Channels where the bot is helpful vs disruptive (adjust permissions)

Troubleshooting

Bot Shows Offline

  • Verify the Discord token is correct in Molty
  • Check that the gateway is running
  • Ensure the Message Content Intent is enabled in Discord Developer Portal

Bot Does Not Respond to Messages

  • Confirm the bot has "Read Messages" and "Send Messages" permissions in the channel
  • Check if the bot is being mentioned or if it is in a channel with active mode
  • Review gateway logs in the Molty dashboard

Bot Responds Slowly

  • Try a faster AI model
  • Check if web search or other tools are causing delays
  • Ensure the gateway region is optimal for your server's user base

Permission Errors

Discord permissions can be confusing with role hierarchies. If the bot cannot perform an action:

  1. Check server-level permissions for the bot's role
  2. Check channel-specific permission overrides
  3. Make sure the bot's role is high enough in the role hierarchy

Going Further

Once your Discord bot is running well, explore additional possibilities:

  • Multi-channel deployment - Add the same Moltbot gateway to WhatsApp, Telegram, or Slack for a unified AI presence
  • Custom tools - Enable web browsing, file handling, or other capabilities
  • Team management - Let multiple admins manage the bot through Molty's dashboard
  • Analytics - Track usage patterns to continuously improve the bot's effectiveness

Discord's rich feature set combined with Moltbot's AI capabilities creates a powerful tool for any community. Start simple, listen to your users, and build from there.

Continue reading