Go to file
2022-10-22 19:32:54 +02:00
.gitignore Init 2022-10-19 23:49:33 +02:00
bot.py Had to fix coolness factor. Not cool. 2022-10-22 15:40:20 +02:00
config.json Init 2022-10-19 23:49:33 +02:00
README.md „README.md“ ändern 2022-10-22 19:29:50 +02:00
update.sh Added user service and changed update script accordingly 2022-10-22 19:32:42 +02:00

Sample Discord Bot with self update

Prerequisites

  • Python 3.8 or higher
  • Git
  • (optional) systemd or equivalent, restarting the bot might be a bit messy otherwise

Installation

  • Just clone the repository to wherever you like
  • If you run systemd, create a service. For example:
# discord-bot.service

[Unit]
Description=Test Discord Bot
After=multi-user.target

[Service]
Type=simple
WorkingDirectory=/home/marco/Projects/DiscordBot
ExecStart=/usr/bin/python3.10 /home/marco/Projects/DiscordBot/bot.py

[Install]
WantedBy=multi-user.target
  • If you don't run systemd, you have to edit the update script to something like
pkill -f 'bot.py'
git pull origin master
python3 bot.py

(optional) Setting up systemd user service

Systemd only allows system wide services out of the box. Those require root access though. If you don't wanna run the bot on an account with root access, here's what you can do:

On an account with root access run:

loginctl enable-linger <username>           // This will enable a user specific service manager

More on that here.

Now reboot your system and log in to the non-root account.

You have to check two environment variables:

echo $XDB_RUNTIME_DIR               // should return something like /run/user/1001
echo $DBUS_SESSION_BUS_ADDRESS      // should return something like /run/user/1001/bus

Now you can create user services under /home/<username>/.config/systemd/user.

To control the service you then can do:

systemctl --user [start/stop/restart] <service name>

To have the service start on boot do:

systemctl --user enable <service name>