How to install and host your own bot instance (old)
This guide only cover Member Counter 0.14 and lower, please, check out this new guide
If you still don't know where to host the bot, try DigitalOcean, with this link you'll get $100 of credit for 60 days, and I'll earn some credit as well to keep up Member Counter! https://m.do.co/c/360e7314770e
If you have any problem during the process, join in this discord server and feel free to ask in the support channel
Recommendations
Have patience
Be familiarized with the CLI (cmd.exe, bash)
Use linux if you wanna host this bot 24/7 (unless you already know how to do it in your OS)
Prerequisites
NodeJS 14.0 or higher
You can download and install the mongoDB community server for free
Or rent a mongoDB Atlas instance (there are also some free plans)
I strongly recommend to install MongoDB in your machine due to a easier and faster access.
You must have already a bot account created in the Discord Developer Portal
You must have enabled all the privileged intents (in the bot tab in Discord Developer Portal)
1. Download the bot to your computer
Clone/download the repository -> https://github.com/eduardozgz/member-counter-bot
2. Set environment variableshere
Never share a .env file: It contains sensitive data
Here is a quick look to the .env.example
If you are using a service like heroku you can take advice of the available environment variables in the .env.example
Enable the developer mode in your discord client User settings > Appearance > Advanced > Developer Mode
Copy and paste the .env.example
file and rename it to .env
(if you can't do this, then you must set the variables directly, search on internet how to do it in your platform, e.g: "how to set env vars in linux" or "how to set env vars in heroku"), then create a dist
folder and move the .env
file there, and open it with a text editor. Below I will explain what does each necessary variable.
DISCORD_CLIENT_TOKEN
Paste here your bot's token, and remember to keep it secret!DISCORD_CLIENT_ID
Paste here your bot's id and add an*
at the end.DB_URI
If you installed mongodb, this varaible should be set tomongodb://127.0.0.1:27017/memberCounter
.DISCORD_PREFIX
feel free to change this value to your favorite bot prefix, but be careful to don't use the same as other botsBOT_OWNERS
Right click your username in the discord client and press "Copy ID" and paste it here and add an*
at the end, you can add as many users as you want separated by a comma (,
). Any user added here will have always full access to the bot's commands without any restriction.UPDATE_COUNTER_INTERVAL
(Seconds) This value will change the frequency of some counter updates, you should set this at least to300
seconds.FOSS_MODE
Set this totrue
, the bot wont kick itself when it join in a no premium serverPREMIUM_BOT
Set this totrue
, to enable all the premium countersPORT
Set this to8080
, or any available port, don't set this if you are using a service like HerokuYOUTUBE_API_KEY
Paste here your YouTube API key, you can get it hereTWITCH_CLIENT_ID
andTWITCH_CLIENT_SECRET
Paste here your Twitch app credentials, you can get them hereTWITTER_CONSUMER_KEY
,TWITTER_CONSUMER_SECRET
,TWITTER_ACCESS_TOKEN
,TWITTER_ACCESS_TOKEN_SECRET
Paste here your Twitter API credentials, you can get them here
3. Install dependencies and build
You must have Python and a C/C++ compiler in order to install some of the bot's dependencies, please follow the install instructions for your operating system: https://github.com/nodejs/node-gyp#installation
4. Check that it works
Start it in your terminal with
npm start
ornode .
Add the bot to your server with one of the following methods:
One of the first line of the logs should contain a URL saying "Basic status website ready", access to it in your browser and click "Invite bot", by using this method you can check that the database and the discord connection is working correctly
Or you can generate a link in the Discord Developer Portal -> click in your bot, click in OAuth2, in the scope section click 'bot' and then will appear more options, click in 'Administrator' and copy the generated link
Testing the bot: (remember to replace
mc!
with your custom prefix)Send
mc!help
Send
mc!guide
Send
mc!counts
If you were able to run the commands successfully without any error, congrats, the bot works.
5. Keep it running, forever.
Method 1 (UNIX and Linux)
Install pm2
cd to the bot folder and run this command
Run this so the bot starts automatically when you boot your computer
Done! Here is some commands:
Check logs:
Start/Restart/Stop
You can learn more about pm2 here
Method 2 (Linux with systemd)
cd to the bot folder and then cd to the
dist
folderCheck that
index.js
has execution permissions for you (and try it by running the bot directly in the terminal with./index.js
)Edit the
res/member-counter-bot.service
file, change the path ofExecStart
andWorkingDirectory
to the real one and change theUser
andGroup
values to yours.Copy this file to
/etc/systemd/system
Enable the service and start it
Check the logs with
journalctl
Repeat the step 4.3
Discard changes of member-counter-bot.service of this repo to avoid conflicts if you update the bot in a future.
Last updated