Discord Bot

Set up a Discord bot with API access for messaging, moderation, and server management.

⏱ 10 minutes messaging social discord.com/developers
getapi discord

Prerequisites

  • A Discord account
  • A Discord server where you have 'Manage Server' permission (or create a test server)

Credentials

Variable Description Sensitive
DISCORD_BOT_TOKEN Bot token for authenticating your bot with the Discord API Secret
DISCORD_APPLICATION_ID Application ID (also called Client ID) for your bot Public

Setup Steps

  1. 1 Info

    We'll create a Discord application and bot, then get the credentials you need. You'll also need to invite the bot to a server.

  2. 2 Open URL

    Opening the Discord Developer Portal. Sign in with your Discord account if prompted.

    https://discord.com/developers/applications
  3. 3 Choice

    Do you already have a Discord application, or do you need to create one?

  4. 4 Info

    Click 'New Application' in the top right. Give it a name (this will be your bot's default username) and accept the terms of service.

  5. 5 Confirm

    Application created? You should see its General Information page.

    Checkpoint — confirm before continuing
  6. 6 Info

    Click on your existing application to open its settings.

  7. 7 Input

    On the 'General Information' page, copy the 'Application ID' and paste it here:

    → DISCORD_APPLICATION_ID
    17–20+ characters
  8. 8 Info

    In the left sidebar, click 'Bot'. If you haven't already, click 'Add Bot' and confirm. Under 'Privileged Gateway Intents', enable the intents your bot needs (Message Content Intent is required to read message text).

  9. 9 Confirm

    Bot section configured?

    Checkpoint — confirm before continuing
  10. 10 Info

    On the Bot page, click 'Reset Token' to generate a new bot token. You'll need to confirm with your password or 2FA code.

  11. 11 Input

    Copy the bot token and paste it here (it won't be shown again):

    → DISCORD_BOT_TOKEN
    At least 24 characters
  12. 12 Info

    Now let's invite the bot to your server. Go to 'OAuth2' > 'URL Generator' in the left sidebar. Under 'Scopes', select 'bot'. Under 'Bot Permissions', choose the permissions your bot needs. Copy the generated URL at the bottom.

  13. 13 Confirm

    Open the generated URL in your browser, select your server, and authorize the bot. Done?

    Checkpoint — confirm before continuing
  14. 14 Validate

    Checking your bot token works...

    Bot token verified. Your Discord bot is ready.
    Couldn't verify the bot token. Make sure you copied it correctly and the bot hasn't been deleted.

Things to Know

  • Bot tokens are shown only once after reset. If you lose it, you'll need to reset it again (which invalidates the old token).
  • The 'Message Content Intent' is a privileged intent. For bots in over 100 servers, you need to apply for verification to use it.
  • Discord rate limits are per-route. Respect the rate limit headers to avoid getting your bot temporarily banned.
  • Bot permissions are determined both by the OAuth2 invite URL AND the role assigned to the bot in the server.
  • For slash commands, you'll also need the 'applications.commands' scope in the OAuth2 URL.