A Discord bot is an automated account that joins Discord servers. It understands commands, reacts to events, sends messages and connects to other systems.
How it works
You create an application in the Discord developer portal, add a bot to it and receive a token. This token is secret and should be stored in an environment variable.
Then you invite the bot to your server via a link generated in the portal, choosing the permissions it will have. Only grant what is necessary.
The code uses a library, such as discord.js (JavaScript) or discord.py (Python), to connect to Discord and respond to events. Modern commands are slash commands, typed with a slash, like /help.
npm install discord.jsThe bot needs to run somewhere, like a server or VPS, to stay online.
Practical example
A programming community wants to welcome newcomers. The bot sends a message with the rules and assigns an initial role. It also offers the /vaga command, which shows opportunities saved in a spreadsheet.
An AI agent can summarize long discussions in a channel and answer frequent questions based on the project's documentation.
What it's for
- Moderate the server and remove spam.
- Welcome members and distribute roles.
- Notify about new videos, releases or sales.
- Create games, polls and giveaways.
- Connect the server to team tools.
Cautions
Bots with too many permissions are a risk: if the token leaks, someone can control your server. Prefer minimal permissions and generate a new token if you suspect a leak.
If the bot stores member data, explain this in the server rules and keep only what is essential. Also read Discord's developer policies before publishing the bot for other communities.