A Discord bot that monitors SWSH albums and posts new photos to a Discord channel.
-
Install dependencies:
npm install
-
Create a
.envfile with your credentials (see.env.example):DISCORD_TOKEN=your_discord_bot_token_here DISCORD_CHANNEL_ID=your_channel_id_here SWSH_API_KEY=your_swsh_api_key_here POLL_INTERVAL_MS=60000
-
Set up Discord Bot:
- Go to Discord Developer Portal
- Create a new application
- Enable bot capabilities and get your bot token
- Invite the bot to your server with proper permissions (Send Messages, Embed Links)
- Get the channel ID where you want photos posted
Development mode:
npm run devProduction mode:
npm start-
Install dependencies on the server:
npm install
-
Edit the systemd service file (
swsh-discord.service):- Replace
swshbotwith your Linux username (or keep it if you create a dedicated user) - Replace
/opt/swsh-botwith the full path to this project - Ensure npx path is correct (check with
which npx)
- Replace
-
Copy the service file to systemd:
- Replace
YOUR_USERNAMEwith your Linux username - Replace
/path/to/swsh-discordwith the full path to this project - Ensure Node.js path is correct (check with
which node)
- Replace
-
Copy the service file to systemd:
sudo cp swsh-discord.service /etc/systemd/system/
-
Enable and start the service:
sudo systemctl daemon-reload sudo systemctl enable swsh-discord sudo systemctl start swsh-discord -
Check status and logs:
sudo systemctl status swsh-discord sudo journalctl -u swsh-discord -f
Managing the service:
sudo systemctl stop swsh-discord # Stop the bot
sudo systemctl restart swsh-discord # Restart the bot
sudo systemctl status swsh-discord # Check status- The bot polls the SWSH API at the interval specified in
POLL_INTERVAL_MS - For each album, it checks if there's a new photo (first photo in the album)
- If a new photo is detected, it posts an embed to the Discord channel
- Photo IDs are tracked in
state.jsonto avoid re-posting