How to make a Discord bot:
create it, get a token and invite it

Create the bot in the Discord Developer Portal, get its token and invite it to your server. Then write a program that logs in with that token to bring the bot online.

Updated 5 min read vProxy Cloud team

vPanel Packages page for a Discord bot (Chinese interface): the package.json dependency list, npm install on every start, and discord.js ^14.16.0 being added

Create the application and bot

Every Discord bot belongs to an application, so you create the application first. A Discord account is all you need for that part. Writing the code later takes a computer with Node.js or Python installed. The Developer Portal is in English only.

  1. Create an application

    Open the Discord Developer Portal in your browser and log in. Click New Application, give it a name, accept the terms and create it.

  2. Set the bot's name and avatar

    Choose Bot in the left sidebar. The name and avatar here are what members see in your server.

  3. Generate a token

    On the same page, click Reset Token and copy the string that appears. You’ll need it when you write the code.

  4. Turn on intents if you need them

    The switches are under Privileged Gateway Intents, further down the Bot page. A bot that only uses slash commands leaves them all off. Message Content Intent lets the bot read the text of regular messages, and Server Members Intent covers members joining and leaving. Turn one on only when the bot uses it.

Where to find and reset the token

The token is generated on the Bot page of the Developer Portal and shown only once, right after you click Reset Token. It disappears when you leave the page. If you lose the token or think it has leaked, go back to the Bot page and click Reset Token again. The old token stops working immediately, so replace it in your program and on your server, then restart the bot to bring it back online.

The token is the bot's username and password in one. Don't paste it into a Discord channel, show it in a screenshot or push it to a public GitHub repository.

Generate an invite link

To add the bot to a server, you need the Manage Server permission on that server.

  1. Open the URL Generator

    Choose OAuth2 in the left sidebar and scroll down to OAuth2 URL Generator.

  2. Select the scopes

    Check bot and applications.commands. Without the second one, slash commands won't appear.

  3. Select the permissions

    Under Bot Permissions, check only what the bot really uses, such as Send Messages and Read Message History. Don't tick Administrator as a shortcut.

  4. Open the link and pick a server

    Copy the URL generated at the bottom, open it in your browser, choose the server and click Authorize. The bot shows up in the member list but stays offline until your program runs.

JavaScript example (discord.js)

Install Node.js first, using the version the discord.js guide asks for. Create a new folder and run these two commands inside it.

npm init -y
npm install discord.js dotenv

In the same folder, create a file named .env and paste your token after the equals sign. Leave out spaces and quotes.

DISCORD_TOKEN=paste-your-token-here

Next, create index.js. When the bot comes online, it registers a /ping command and answers pong whenever someone uses it.

require('dotenv').config();
const { Client, Events, GatewayIntentBits } = require('discord.js');

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.once(Events.ClientReady, async (c) => {
  await c.application.commands.set([{ name: 'ping', description: 'Replies with pong' }]);
  console.log(`Logged in as ${c.user.tag}`);
});

client.on(Events.InteractionCreate, async (interaction) => {
  if (!interaction.isChatInputCommand()) return;
  if (interaction.commandName === 'ping') await interaction.reply('pong');
});

client.login(process.env.DISCORD_TOKEN);

Run node index.js. Once “Logged in as” appears, the bot shows as online in Discord. Try /ping.

Python example (discord.py)

The discord.py documentation lists which Python version to install. With Python in place, install these two packages. The bot reads the same .env file as the JavaScript example.

pip install -U discord.py python-dotenv

Create app.py. It does the same thing as the JavaScript example.

import os
import discord
from discord import app_commands
from dotenv import load_dotenv

load_dotenv()

client = discord.Client(intents=discord.Intents.default())
tree = app_commands.CommandTree(client)


@tree.command(name="ping", description="Replies with pong")
async def ping(interaction: discord.Interaction):
    await interaction.response.send_message("pong")


@client.event
async def on_ready():
    await tree.sync()
    print(f"Logged in as {client.user}")


client.run(os.environ["DISCORD_TOKEN"])

Run python app.py. The example syncs commands every time the bot starts. Once you have more commands, sync only when they change.

Run it 24/7 on a server

To keep the bot online, move the whole folder to a machine that stays on and run it there. Leave node_modules behind, because the server installs the packages again. If you deploy from GitHub, keep .env out of the repository and put it on the server separately.

Once the files are uploaded, the Setup wizard in the new vPanel lets you pick the main file and version, and pushes to GitHub can deploy automatically. The .env template the Setup wizard creates uses the same variable name as the examples, DISCORD_TOKEN. vPanel can be switched to English from the menu in the top-right corner.

After pasting the token, press Start. When the line printed by the sample code appears in the console, the bot has logged in.

The vPanel console: npm install adds the packages, node index.js runs, and the last line reads 已上線:DemoBot#1234 (Chinese for online)
The console once the bot is online. The last line comes from the Chinese version of the sample, which prints 已上線: where the code above prints Logged in as (demo screen).

To link a Minecraft server's chat with a Discord channel, give the DiscordSRV plugin the token of the bot you just made.

References

FAQ

Is the token the same as the Client Secret?
No. Your program logs in with the Token from the Bot page. The Client Secret on the OAuth2 page is for website login features, and most bots never use it.
The bot joined my server but always shows as offline. Why?
Your program is not running. Inviting the bot only adds it to the server. It comes online when your program logs in with the token, and goes offline as soon as the program stops.
I get Used disallowed intents when the bot starts.
Your program asks for an intent that is not turned on in the Developer Portal. In discord.py the error is PrivilegedIntentsRequired. Turn on the matching Privileged Gateway Intent on the Bot page, or remove the intents you do not use from your code.
Typing / doesn't show my bot's commands.
First make sure the invite link included applications.commands and that your program started without errors, then press Ctrl+R in the Discord app to reload.
Does making a Discord bot cost money?
Creating a bot is free. Keeping it online 24/7 means running the program on a computer or server that never shuts down, and that is the part that costs money.
Can I make one without knowing how to code?
You need a little JavaScript or Python. Copy the example and get it running first, then add features by following the official discord.js or discord.py guides.

vProxy Cloud customers who are still stuck can open a support ticket in the client portal. Select the server the ticket is about and include the error from the console.

Service status

Host your Discord bot

Plans from NT$29/mo. Supports JavaScript, Python, Java and GoBilled every 30 days