What a Discord bot is and why you might want one

A Discord bot is a program that runs inside a Discord server and performs tasks automatically or when you give it commands. Bots can welcome new members, moderate messages, play music, keep score in games, or fetch information from the internet — all without a human typing each response. You create one by writing code, uploading it to a hosting service, and connecting it to your Discord server through Discord's developer portal.

Most people create bots for servers they run themselves or help manage. A bot saves time on repetitive work and can do things faster than a person could type them. If you run a gaming server, a bot can track wins and losses. If you run a study group, a bot can post reminders. The code you write determines what the bot does.

Key Takeaways

  • You need a Discord account, a code editor, and Python or JavaScript installed on your computer to start building a bot.
  • The Discord Developer Portal is where you create your bot's identity and get the token that lets it log into Discord.
  • You write the bot's behavior in code using a library like discord.py or discord.js, which handles the connection to Discord for you.
  • Your code runs on a hosting service (free or paid) so the bot stays online even when your computer is off.
  • You invite the bot to your server through a special link generated in the Developer Portal, then test commands in a text channel.

Create your bot in the Discord Developer Portal

Go to discord.com/developers/applications and log in with your Discord account. Click the blue "New process" button in the top right. Type a name for your bot — this is what will appear in your server's member list. Click "Create" and you will see a settings page for your new process.

On the left sidebar, click "Bot" and then the blue "Add Bot" button. Discord creates a bot account linked to your process. You will see a section called "TOKEN" with a long string of characters hidden behind dots. Click "Copy" to copy this token to your clipboard. Do not share this token with anyone — it is like a password that lets someone control your bot. If you accidentally post it online, click "Regenerate" to create a new one and the old one stops working.

Scroll down to "Intents" and turn on "Message Content Intent" if you want your bot to read the text of messages in your server. Without this, your bot can see that a message was sent but not what it says. Leave other intents off unless your bot needs them — fewer intents means fewer permissions and lower risk if the token leaks.

Set up your coding environment

You will write your bot's code on your computer using a code editor and a programming language. The two most common choices are Python with the discord.py library or JavaScript with the discord.js library. Python is simpler for beginners; JavaScript is faster for complex bots. Pick one and stick with it for your first bot.

read and install Python from python.org (choose the latest version) or Node.js from nodejs.org (which includes JavaScript). read a free code editor like Visual Studio Code from code.visualstudio.com. Open the editor, create a new folder for your bot project, and create a new file called bot.py (for Python) or bot.js (for JavaScript).

Open a terminal or command prompt in your bot folder. If you chose Python, type pip install discord.py and press Enter. If you chose JavaScript, type npm install discord.js and press Enter. This downloads the library that lets your code talk to Discord. Wait for the read to finish — you will see a message saying the install succeeded.

Write your first bot command

Here is a straightforward Python bot that responds when someone types !hello. Paste this code into your bot.py file:

import discord from discord.ext import commands bot = commands.Bot(command_prefix='!', intents=discord.Intents.default()) @bot.event async def on_ready():     print(f'{bot.user} has logged in') @bot.command(name='hello') async def hello(ctx):     await ctx.send(f'Hello {ctx.author.name}!') bot.run('YOUR_TOKEN_HERE')

Replace 'YOUR_TOKEN_HERE' with the token you copied from the Developer Portal. Save the file. Open your terminal in the bot folder and type python bot.py (or node bot.js for JavaScript). If the code has no errors, you will see a message saying your bot has logged in. The bot is now running on your computer and listening for commands.

This code does three things: it creates a bot that listens for commands starting with !, it prints a message when the bot logs in successfully, and it defines a command called hello that replies with a greeting. When someone types !hello in your server, the bot will respond with "Hello [their name]!"

Invite your bot to your Discord server

Go back to the Discord Developer Portal and click on your process. On the left sidebar, click "OAuth2" and then "URL Generator". Under "Scopes", check the box next to bot. Under "Permissions", check Send Messages, Read Messages/View Channels, and any other permissions your bot needs. A URL will appear at the bottom of the page — copy it.

Paste the URL into your browser and you will see a dropdown asking which server to add the bot to. Select your server and click "Authorize". Discord will ask you to confirm that you want to give the bot those permissions. Click "Authorize" again. The bot will now appear in your server's member list.

Go to a text channel in your server and type !hello. Your bot should reply with a greeting. If it does not, check that the bot is still running on your computer — if you closed the terminal, the bot stopped. Restart it by typing python bot.py again.

Move your bot to a hosting service so it stays online

Right now your bot only runs when your computer is on and the terminal is open. To keep it running 24/7, you need to host it on a server. Free options include Replit (replit.com), Railway (railway.app), or Heroku (heroku.com) — each has a free tier with limits. Paid options like DigitalOcean or AWS cost a few dollars a month but are more reliable.

For a beginner, Replit is the easiest: create an account, click "Create Repl", choose Python or Node.js, paste your bot code into the editor, and click "Run". Replit keeps your bot online as long as your account is active. Railway and Heroku require more setup but work the same way — you upload your code and they run it on their servers.

Once your bot is hosted, you can close the terminal on your computer and the bot will keep running. Test it by typing a command in your Discord server. If it responds, your bot is online and working.

Frequently Asked Questions

What if my bot does not respond to commands?

Check three things: the bot is still running (look for the terminal window or check your hosting service), the bot has permission to send messages in that channel (right-click the channel, click "Edit Channel", and check the bot's permissions), and you typed the command correctly with the right prefix (usually !).

Can I make my bot do something without a command, like react to every message?

Yes. Instead of using the @bot.command decorator, use @bot.event and the on_message function. This runs code every time someone sends a message. Be careful not to make your bot spam — Discord will slow it down or ban it if it sends too many messages too fast.

What happens if someone gets my bot token?

They can control your bot and use it to spam, delete messages, or harm your server. Go to the Developer Portal when ready, click "Regenerate" under the TOKEN section, and update the token in your code. The old token stops working right away.

Do I need to know how to code to create a bot?

You need to learn the basics of Python or JavaScript, but you do not need to be an informed. Start with straightforward commands like the !hello example, then add features one at a time. Discord.py and discord.js have good documentation and many tutorials online.

Can I use my bot in other people's servers?

Yes. Generate the OAuth2 URL in the Developer Portal and share it with anyone who wants to add your bot to their server. They will see a permission screen and can choose to authorize it. You cannot control which servers use your bot once you share the link.