UnionRolistes.fr
Fonctionnalité du Bot Discord De UnionRolistes.fr, opensources
Installation
-
You need node installed on your system, detailled instructions for different operating systems can be found here.
-
Check your node version with
node -v
. Node.js 12.0.0 or newer is required. -
Cloning the project via git. OneLine Update
cd /usr/local/src/
sudo git clone https://github.com/UnionRolistes/Bot-Roles BotRolesList && cd ./BotRolesList/ && sudo npm install && sudo npm run install
pm2 status && pm2 delete 0 && pm2 start index.js
-> Default Directory -> Create a new folder -> Clone the project in the folder you just created. -> Go into the folder where you cloned the project.
Before setting up the "real" bot you must check some things:
- You need a so called token for your bot. You need it later.
-> How to obtain the token? Create an application and follow the steps below:
Now navigate to "Bot"
-
Since Discord restricted the access to specific user data, you need to enable the so called Privileged Gateway Intents. To so, scroll down and enable both of them And click "Copy"
-
A suitable prefix. There is no sense in choosing one which another bot already utilises. So choose a unique one.
-
Install the packages with
sudo npm install
-
Execute
sudo npm run install
to create a configuration file before the first startup of the bot.
- prefix : This will be the prefix for which the bot will listen(I suggest $).
- token : Token which you obtained earlier.
- intents : Don't touch the next options! If you're interested why check out this discord post.
- Run the bot
node index.js
.
Keeping it online with PM2
PM2 is an advanced, production process manager for Node.JS.
The Documentation can be found here.
Install it globally:
sudo npm install pm2 -g
Now navigate to the folder with the bot. ( cd /.....)
pm2 start index.js
You can also specify more options:
# Specify an app name
--name <app_name>
# Watch and Restart app when files change
--watch
# Set memory threshold for app reload
--max-memory-restart <200MB>
# Specify log file
--log <log_path>
# Pass extra arguments to the script
-- arg1 arg2 arg3
# Delay between automatic restarts
--restart-delay <delay in ms>
# Prefix logs with time
--time
# Do not auto restart app
--no-autorestart
# Specify cron for forced restart
--cron <cron_pattern>
# Attach to application log
--no-daemon
Now everything is done! Check the status of pm2 with
$ pm2 status
Managing processes
Managing application state is simple here are the commands:
pm2 restart app_name
pm2 reload app_name
pm2 stop app_name
pm2 delete app_name
Instead of app_name you can pass:
- all to act on all processes
- id to act on a specific process id
For more informations check the documentation -> https://pm2.keymetrics.io/ and the quickstart guide -> https://pm2.keymetrics.io/docs/usage/quick-start/
Updating the code
First of all we have to stop the process manager pm2
Execute: pm2 status
to get the id or the name of your app
(Since we only have one here, the id should 0 and the name should be index)
Now stop the process with pm2 stop (name/id)
in this case -> pm2 stop index
Now update the code in the respective folder via Git.
go into the folder: cd....
git clone https://github.com/Myst82015/L-Union-des-R-listes.git
Then npm run install
(just in case I added another npm module)
npm run install
( in the folder where the code is in), don't change anything at the preselected intents!
Update on 16.10.2020: IMPORTANT: To fix the problems with the incorrect membercounts go to setup guide above and check the intents (below point 4). Then regenerate the config You're nearly done!
Navigate in the folder with the bot (cd ./....)
and daemonize it with pm2
pm2 start index.js
Finally check the status of the process with pm2 status
.