AVARIXO

Type and hit Enter to search

Discord bot chat interface for Disboard bot guide
AI & TechInternet

How to Make a Discord Bot in 2026: Free Slash Command Tutorial

AVARIXO
October 13, 2026 7 Mins Read
38 Views
0 Comments

Quick answer: To make a Discord bot, create an application in the official Discord Developer Portal, configure its bot user, install it in a test server with limited permissions, and run code that responds to an application command such as /ping. You can develop this example locally with Node.js and the discord.js library without paying for a Discord bot account. Continuous hosting is optional and may cost money, depending on where you run the bot.

This tutorial uses a slash command, not a message-reading bot. That matters: you do not need the privileged Message Content intent to answer a user who deliberately runs your /ping command. The screenshots and application layout can change, but the configuration concepts follow Discord’s official application-command documentation.

What You Need Before Creating a Bot

  • A Discord account with permission to create applications and install an app in the server you plan to test.
  • A test server where you can manage server settings or install applications.
  • Node.js LTS and npm installed on your computer, preferably using the official Node.js downloads.
  • A code editor for a small JavaScript project. You do not need a dedicated paid bot-builder product.
  • Basic command-line access to run npm and node.

Do not start by requesting Administrator permissions or trying to read every message in a server. Build the smallest useful command first, then add capabilities deliberately.

Step 1: Create the Discord Application

  1. Open Discord’s official Developer Portal and sign in.
  2. Choose New Application, give it a clear name such as “My Practice Helper”, and confirm creation.
  3. Open General Information and copy the Application ID. This identifies your application but is not the secret used to control your bot.
  4. Open the Bot page. Confirm that a bot user is available. Discord’s exact token controls may say Reset Token when you need to generate or replace a token.
  5. Copy the bot token into your local secret configuration, not into the article, a chat, a GitHub repository or a screenshot. If anyone learns it, rotate it immediately in the portal.

Important distinction: An application ID identifies the app in API routes. The bot token authenticates it. A guild ID identifies your test server. None of them are interchangeable, and only the token must always be treated like a password.

Step 2: Install Your Bot in a Test Server

In the Developer Portal, open the app’s Installation or OAuth2 setup area, depending on the interface currently displayed. Set up installation for a server where you have permission. For a bot that responds to slash commands, ensure the required applications.commands capability is included; if your app connects as a bot user, its bot scope must also be authorized. Discord’s installation tooling handles much of the URL construction for you.

  1. Choose a server you control as the test destination.
  2. Request only the permissions actually needed, such as viewing an appropriate channel and sending a response. Do not automatically grant Administrator.
  3. Complete Discord’s authorization screen.
  4. Confirm that the bot appears in the server member list or that the app is installed, depending on the installation setup.

You can have an app in a server before its process is running. Installation does not host a bot or keep it online for you.

Step 3: Set Up a Free Node.js Project

Create an empty folder named my-discord-helper. Open a terminal in that folder and run:

npm init -y
npm install discord.js dotenv

Then create a file named .env. Add your values from the Discord Developer Portal and test-server settings:

DISCORD_TOKEN=replace_with_your_private_bot_token
DISCORD_APP_ID=replace_with_your_application_id
DISCORD_GUILD_ID=replace_with_your_test_server_id

To obtain the server’s ID, enable Developer Mode in Discord’s advanced settings, then use the server’s context menu to copy its ID. Discord may relocate this setting between interface updates.

Create a .gitignore file containing .env and node_modules/. Even in a throwaway test project, make secret handling a habit from the beginning.

Step 4: Write a Working /ping Slash Command

Create index.js containing the example below. It connects the bot, registers one test-server command and answers that command with a short message. Guild-scoped commands are useful during development because their registration is intended for a specific server; do not repeatedly register broad global commands while you are experimenting.

require('dotenv').config();

const {
  Client,
  Events,
  GatewayIntentBits,
  REST,
  Routes,
  SlashCommandBuilder
} = require('discord.js');

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

const commands = [
  new SlashCommandBuilder()
    .setName('ping')
    .setDescription('Check whether the bot responds')
    .toJSON()
];

client.once(Events.ClientReady, async (readyClient) => {
  console.log('Connected as ' + readyClient.user.tag);

  const rest = new REST({ version: '10' })
    .setToken(process.env.DISCORD_TOKEN);

  try {
    await rest.put(
      Routes.applicationGuildCommands(
        process.env.DISCORD_APP_ID,
        process.env.DISCORD_GUILD_ID
      ),
      { body: commands }
    );
    console.log('Guild /ping command registered');
  } catch (error) {
    console.error('Command registration failed:', error);
  }
});

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

  try {
    await interaction.reply('Pong! The practice bot is online.');
  } catch (error) {
    console.error('Reply failed:', error);
  }
});

client.login(process.env.DISCORD_TOKEN);

This is a minimal learning example rather than a production bot architecture. For a larger bot, use separate files to register slash commands, a proper command handler, structured logging, deployment secrets and automated tests. Be mindful of API rate limits and avoid printing token values in error logs.

Step 5: Start the Bot and Test It

  1. Run node index.js in the same folder as the project and .env file.
  2. Wait for a successful connected message and, shortly afterward, the guild command-registration result.
  3. Open a text channel where the app can be used.
  4. Type /ping and choose your application’s command from the picker.
  5. Submit the command. The bot should respond with Pong! The practice bot is online.

Keep the terminal process running while testing. Closing that terminal or stopping the Node.js process generally disconnects the bot. You cannot make a local bot remain online merely by adding it to a server.

How Slash Commands Work Under the Hood

When a user selects /ping, Discord delivers an interaction to the app. The command’s name, description and any option definitions were registered ahead of time. The running bot listens for InteractionCreate, filters for chat-input commands and replies using the interaction response mechanism. This differs from watching every incoming message for a prefix such as !ping.

Some Discord apps process interactions through outgoing HTTP requests instead of a Gateway connection. This guide intentionally uses the Gateway approach because it is straightforward for a small local JavaScript project. If you later use an HTTP interactions endpoint, you must validate the signatures Discord sends.

Fixes for the Five Most Common Discord Bot Errors

“Invalid Token” or failed login

Check that .env exists in the project root, that you have copied the entire current bot token and that the variable is named exactly DISCORD_TOKEN. If the token was exposed or accidentally committed, rotate it immediately. Do not test tokens using random third-party websites.

The bot is online but /ping is not listed

Check the app installation, the applications.commands scope and the correct test-server ID. Review the terminal for command-registration errors. Guild-scoped command changes should generally be faster to test than global ones. Restart Discord’s client if the command picker appears stale.

Missing Access or Missing Permissions

Ensure that the bot was installed in the intended guild and allowed in the channel. Permission denials can come from server roles or specific channel overrides. Do not fix this by granting full Administrator unless a specific administrative feature genuinely requires it.

Cannot find module ‘discord.js’

Open the terminal inside the correct project folder and run npm install discord.js dotenv. Confirm your installed Node.js version is supported by the installed library release.

The bot disappears when my PC is off

Your process stopped. To keep a bot online, run it on a computer or hosting environment that stays active. Many hosting plans have usage limits, sleeping behavior or fees; do not assume an advertised free service provides uninterrupted operation.

Should You Build a Bot With Code or a No-Code Tool?

ApproachBest forTrade-off
Discord.js with Node.jsCustom logic, slash commands, learning developmentRequires writing and maintaining code
Python with discord.pyDevelopers who prefer PythonRequires a different library and deployment setup
No-code bot-builder serviceSimple routine workflows and fast prototypesPlan limitations, service dependencies and possibly paid features
Installing an existing botModeration, utility commands, ready-made featuresLess control over behavior, privacy and permissions

If all you want is a music bot or an automatic moderation feature, you may not need to write code. See our comparison of Discord music bot options. If you’re managing servers during development, review the Discord server deletion checklist before experimenting with destructive administration tasks.

Three Safe Improvements After Your First Command

  1. Add a /help command: List the supported commands and their intended use; do not make users guess undocumented features.
  2. Add user-friendly validation: For a command that accepts text, check type, length and permissions before returning a result.
  3. Log only what you need: Record command names, timestamps and non-sensitive errors. Avoid storing message content or users’ personal information by default.

Build one feature at a time and retest in a private server. If you move from a small guild test to public installation, review Discord’s app verification, privacy and security requirements as applicable.

Discord Bot FAQ

Does making a Discord bot cost money?

Creating an application and building a basic bot using local development tools does not require a separate fee to Discord. A server that runs it 24/7 may involve hosting costs, and paid third-party bot tools are optional.

Can I make a Discord bot without code?

Some services provide configurable bots, but feature limits and prices vary. Writing your own bot gives you more control and reduces reliance on a builder’s templates.

Do I need the Message Content intent?

Not for the /ping slash-command example above. Slash commands are interactions; reading ordinary message text for custom prefix commands is a different capability with additional requirements.

Why can’t I see my new bot in the server?

Creating the application alone does not install it. Complete an authorized app installation to your test server and check that the chosen installation context and scopes are appropriate.

Can a bot run on my phone?

A phone may be able to manage a bot through a specialized environment, but it is not the same as reliable production hosting. Most beginners find a desktop for development and a dedicated running environment for availability simpler.

Official References and Screenshot Attribution

Primary documentation: Discord Developer Quick Start, Application Commands, and discord.js Guide. Review the documentation if the Developer Portal UI or library API changes.

Featured screenshot: Sparkfire298 / Wikimedia Commons, released into the public domain (CC0 statement). The screen shows a third-party Pigeon bot conversation, not the exact sample bot created in this tutorial; it is included only as a real example of how a bot appears in Discord.

Share Article

Follow Me Written By

AVARIXO

Other Articles

Exclusive topic-specific AVARIXO visual about ungoogled chromium
Previous

Ungoogled Chromium Explained: Privacy Trade-Offs, Updates and Extensions

Unique editorial diagram about spotify app mac
Next

Spotify App for Mac: Official Download, Install and Audio Troubleshooting

Next
Unique editorial diagram about spotify app mac
October 13, 2026

Spotify App for Mac: Official Download, Install and Audio Troubleshooting

Previous
October 13, 2026

Ungoogled Chromium Explained: Privacy Trade-Offs, Updates and Extensions

Exclusive topic-specific AVARIXO visual about ungoogled chromium

No Comment! Be the first one.

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    AVARIXO
    Gaming AI & Tech Entertainment Internet Alerts Sports
    More ⌄
    AVARIXO ToolsCalculators & converters Original DataTrackers & live datasets
    ☰
    ToolsOriginal Data Gaming AI & Tech Entertainment Internet Alerts Sports Deals Money News & Explainers Travel
    More⌄
    ⚡Avarixo ToolsCalculators & converters ◈Original DataTrackers & live datasets
    AVARIXO

    A fresh perspective on your digital world. Explore useful guides, free everyday tools, and original data.

    Explore AVARIXOGamingAI & TechEntertainmentInternetAlertsSportsFree ToolsOriginal Data
    About & ResourcesAboutContactEditorial PolicyPrivacy PolicyTermsDisclaimer
    © 2026 AVARIXO. All rights reserved.Know More. Sooner.