How to Create a Chatbot in Discord

A Discord bot can do everything available in other channels, plus interact directly with your server: reply in channels, threads, and direct messages, add reactions, receive and send files, and edit or delete its own messages. Additional features include moderation (timeouts, kicks, bans, and message deletion), role management, creating channels for tickets, and slash commands.

The setup takes about ten minutes and consists of two parts: first, create the bot on the Discord side, then connect it to your project in Mavibot.

Step 1. Create an Application

Open the Discord Developer Portal and click New Application. Enter a name — server members will see it.

In the Installation section, set Install Link to None. You will create the bot installation link yourself in Step 4 with the required permissions.

Step 2. Configure the Bot

Go to the Bot section.

Disable Public Bot. Otherwise, anyone will be able to add your bot to their server.

Enable the required privileged intents — without them, Discord will not send certain data to the bot:

Intent Why It Is Needed
Message Content Intent Message text. Without it, the bot can see that a message was sent but cannot see its content, so text-based triggers will not work.
Server Members Intent Member events: joins, leaves, role changes, and nickname changes. Without it, new-member greetings and automatic role assignment will not work.
Presence Intent Online status. It is not required for the bot to work and does not need to be enabled.

Step 3. Get the Bot Token

In the same Bot section, click Reset Token and copy the token that appears. It is displayed only once — save it, as you will need it in Step 6.

Important! The token provides full access to your bot. Do not publish or share it. If the token is compromised, click Reset Token again. The old token will immediately stop working, and you will need to reconnect the bot in Mavibot using the new token.

Step 4. Select Permissions

Open OAuth2 → URL Generator.

Under Scopes, select:

  • bot — the bot itself;
  • applications.commands — if you plan to use slash commands. Without this scope, commands cannot be registered on the server.

The Bot Permissions section will appear below. Select only the permissions your bot actually needs — it is better not to grant unnecessary permissions.

Minimum Permissions for Messaging

Permission What Will Not Work Without It
View Channels The bot will not be able to see channels at all
Send Messages The bot will not be able to reply
Read Message History Replies to messages and quoting will not work
Embed Links, Attach Files Links with previews and files will not be sent
Add Reactions The bot will not be able to add reactions

Additional Permissions for Moderation and Automation

Permission What It Is Used For
Manage Messages Deleting other users' messages and managing pinned messages
Moderate Members Timeouts (mutes)
Kick Members Removing members from the server
Ban Members Banning and unbanning members
Manage Roles Assigning and removing roles
Manage Nicknames Changing member nicknames
Manage Channels Creating and deleting channels, including ticket channels
Create Instant Invite Creating invitation links

Permissions can also be changed later in the bot role settings on the server without reconnecting the bot.

Step 5. Add the Bot to Your Server

Copy the URL generated at the bottom of the URL Generator page, open it in your browser, and select the server.

Only the server owner or a member with the Manage Server permission can add the bot.

After adding the bot, check the role order:

Server Settings → Roles

The bot's role must be positioned above the roles it will assign and above the roles of members it needs to moderate.

This is a Discord restriction: a bot cannot assign a role that is at the same level as or higher than its own role, and it cannot timeout or ban a member whose role is higher than the bot's role.

Step 6. Leave Interactions Endpoint URL Empty

Return to the General Information section of your application and make sure the Interactions Endpoint URL field is empty.

If anything is specified in this field, Discord stops sending button clicks and slash command interactions to the bot — they are sent to the specified URL instead.

From the user's perspective, this looks like buttons in bot messages are not working, while slash commands return "Application did not respond."

Step 7. Connect the Bot to Your Project

In your Mavibot project, open the Channels section, click Discord, and paste the token from Step 3.

After a few seconds, the bot should appear online on your Discord server. If it does not, make sure the token was copied completely and does not contain extra spaces.

Check That Everything Works

Send a message in any server channel that should trigger one of your bot's responses — the bot should reply.

If the bot is online but does not respond, Message Content Intent is most likely not enabled.

Join the server using another account or ask a colleague to join — the new-member greeting should trigger. If it does not, check Server Members Intent.

Click a button in a bot message. If nothing happens, check the Interactions Endpoint URL.

Important Things to Know

A Channel Conversation Is Shared by Everyone

All channel members write to the same conversation, just like in a group chat.

Variables such as "who sent the message" refer to the author of the latest message and are overwritten by the next message — read and process them immediately in the same block.

Direct messages with the bot and member events such as joins, leaves, and role changes are handled in a separate conversation for that member.

Direct Messages Are Restricted by Discord

A bot can send a direct message to a member only if the member shares a server with the bot and has not disabled direct messages from server members in their privacy settings.

If the member has disabled direct messages, the message cannot be delivered — this is a Discord restriction and cannot be bypassed.

Full Webhook Data

If you assign any value to the save_webhook variable, all incoming event data will be saved to the discord_webhook variable.

This is rarely needed — almost everything you may need from the webhook is already available through separate variables.

Common Issues

What Happens Why
The bot is online but does not respond to text Message Content Intent is not enabled
Join, leave, and role-change events are not received Server Members Intent is not enabled
Buttons do not work and slash commands return "Application did not respond" Interactions Endpoint URL is filled in
Slash commands cannot be registered The bot was added without the applications.commands scope — generate a new installation URL and add the bot again
The bot cannot assign a role The bot's role is not above the target role, or the bot does not have Manage Roles. Roles managed by integrations, including roles of other bots, and the @everyone role cannot be assigned
The bot cannot timeout or ban a member The member's role is higher than the bot's role, or the bot does not have Moderate Members / Ban Members
The bot cannot see a specific channel Channel-level permissions override server-level permissions. Check the bot role permissions in that channel's settings
Messages cannot be deleted The bot does not have Manage Messages. Discord allows bulk deletion only for messages less than 14 days old

What's Next

A Discord chatbot supports the same core features as bots in other channels: it can send messages to channels, threads, and direct messages, add reactions, send and receive attachments, and edit or delete its own messages.

For server management functions available from your bot flow, see "Discord API Functions."

To learn how to build the message flow itself, see "How to Create a Chatbot for Business."

To let AI communicate with customers in Discord, enable an AI Assistant — see the "AI Assistant" section.