A Discord bot is a program that joins your server through a Discord application and answers commands like /ping. This free creator walks you through the Developer Portal, builds a least-privilege link to add the bot to your server, and gives you ready-to-run discord.js slash command code. It never asks for your bot token.
Developer Portal setup checklist
1
Create an application
Open the Discord Developer Portal, choose New Application, and give it a name. This is free and uses your normal Discord account.
On General Information, copy the Application ID and paste it into this page. It is public, so it is safe to share.
3
Get the bot token
On the Bot page, choose Reset Token and copy it straight into your .env file. Discord shows it only once. Never paste it into a website, a chat, or a git commit, including this page.
4
Decide who can add it
On the Bot page, turn Public Bot off if only you should be able to add the bot to servers. Leave privileged intents (Message Content, Server Members, Presence) off: slash commands do not need them.
5
Add the bot to your server
Open the install link below while signed in to Discord and pick a server where you have Manage Server permission.
6
Run the starter code
Install Node.js 22 or newer, download the files below, run npm install, npm run deploy once to register the commands, then npm start. Type / in your server to see the commands.
Build your bot
Everything runs in your browser. Nothing you enter is uploaded or saved.
Commands register in this server only and appear right away. Turn on Developer Mode in Discord settings to copy IDs.
Install link
Enter your Application ID to build the link.
Starter code (discord.js 14, Node.js 22+)
import { Client, Events, GatewayIntentBits, MessageFlags } from "discord.js";
import { commands } from "./commands.js";
// Guilds is the only intent slash commands need. It is not a privileged intent.
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
const byName = new Map(commands.map((command) => [command.data.name, command]));
client.once(Events.ClientReady, (ready) => {
console.log(`Online as ${ready.user.tag}`);
});
client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isChatInputCommand()) return;
const command = byName.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
const reply = { content: "Something went wrong running that command.", flags: MessageFlags.Ephemeral };
if (interaction.replied || interaction.deferred) await interaction.followUp(reply);
else await interaction.reply(reply);
}
});
client.login(process.env.DISCORD_TOKEN);
cp .env.example .env # then paste your token into .env
npm install
npm run deploy
npm start
Save the files in one folder. Browsers may save .env.example and .gitignore without the leading dot; rename them if so.
Troubleshooting
The command does not show up when I type /
Run npm run deploy again and check that it printed Registered. Add a test server ID so commands register there and appear right away. Global commands can take a while to reach every server, and a Discord client restart (Ctrl+R) refreshes the list.
The app did not respond
The bot process is not running, crashed, or took longer than 3 seconds to reply. Check the terminal where you ran npm start for an error.
The bot shows as offline
npm start is not running, or the token in .env is wrong. If the log says TokenInvalid, reset the token on the Bot page and paste the new one into .env.
Missing Access when registering commands
The bot is not in the server whose ID you set, or the ID is wrong. Add the bot with the install link first, or clear DISCORD_GUILD_ID to register globally.
Missing Permissions when the bot posts
Slash command replies need no permissions, but posting on its own needs View Channels and Send Messages in that channel. Tick them, open the new install link, or give the bot's role those permissions in the channel settings.
Used disallowed intents
The code asks for a privileged intent you have not turned on. The starter uses only the Guilds intent, so remove any extra intents you added or turn them on under Bot, Privileged Gateway Intents.
Create an application in the Discord Developer Portal, copy its Application ID, reset and copy the bot token, add the bot to a server with an install link, then run bot code such as a discord.js script that logs in with the token. This page builds the install link and the code for you.
Is it free to make a Discord bot?
Yes. Creating a Discord application and bot is free. The only cost is somewhere to run the code: your own computer works while it is on, and a server or hosting service keeps the bot online all the time.
What permissions does a Discord bot need?
Only the ones it uses. A bot that just answers slash commands needs no permissions, because replies go through the interaction. Add View Channels and Send Messages if it posts on its own, and avoid Administrator: it gives full control of the server if the token ever leaks.
Is it safe to paste my bot token into a website?
No. The token is the bot's password: anyone who has it can control the bot. Keep it in a .env file on the machine that runs the bot. This tool never asks for it, and if you paste one by mistake it is discarded. Reset it on the Bot page if it was ever shared.
Why do my slash commands not appear?
Commands must be registered before they appear. Run the deploy script once, and use a test server ID while you build so commands show up right away. Also check that the bot was added with the applications.commands scope, which this install link includes.