# How do I run my Discord bot?

https://www.seturack.com/en/knowledgebase/article/how-to-run-my-discord-bot

1. In the panel, open **My servers** and click your server.
2. On the **Overview** tab, wait for the **App** row to say "Discord bot is ready". The page refreshes itself.
3. Note the IP in the **Connection address** row.
4. Create an application in the [Discord Developer Portal](https://discord.com/developers/applications). On the **Bot** page, use **Reset Token** to get your token.
5. [Connect with SSH](https://www.seturack.com/en/knowledgebase/article/how-to-connect-with-ssh) and open the file: `nano /opt/seturack/discord/bot/.env`
6. Paste the token after `DISCORD_TOKEN=` and save. The sample bot connects by itself within seconds.
7. To see what it is doing: `su - app -c "pm2 logs bot --lines 20"`
8. In the portal, open **OAuth2 > URL Generator**, select `bot` and `applications.commands`, then use the link to add the bot to your Discord server. Type `/ping` and the bot answers `pong`.

## Running your own code

Run `su - app`, then `cd /opt/seturack/discord/bot`. Put your code here, replacing `index.js` if you need to:

`npm install`

`pm2 restart bot`

`pm2 save`

## Good to know

- With no token, the process stays up and logs "token bekleniyor / waiting for token". That is normal.
- Keep your token private. Only the bot user can read `.env`.
- PM2 starts the bot when the server boots. The bot takes no incoming connections, so only port **22** for SSH is open.

**No server yet?** [Order a server with Discord botu installed](https://www.seturack.com/en/discord-vps): you choose the size and pay for what you choose.
