Bot (not webhook) for cardiparty announcements
Find a file
2025-06-23 13:43:58 +10:00
.gitignore adjust for cardicast 2024-09-16 10:23:55 +10:00
latest_post.txt adjust for cardiparty forum channel 2025-06-23 13:40:03 +10:00
LICENSE oops 2024-09-15 11:58:31 +10:00
README.md adjust for cardiparty forum channel 2025-06-23 13:40:03 +10:00
requirements.txt adjust for cardiparty forum channel 2025-06-23 13:40:03 +10:00
send_message.py adjust for cardiparty forum channel 2025-06-23 13:40:03 +10:00
trigger.sh update trigger for cardiparty 2025-06-23 13:43:58 +10:00

Discord cardiparty announcement bot

Push new cardiParty announcements into the cardiParties Discord channel using a bot account and the Discord API.

prerequisites

You need to have a server to run this code on, and also a Discord bot account.

  1. Create your bot at https://discord.com/developers/applications
  2. Change registration URL to "none" to make it private, and untick the box for "public bot"
  3. Go to OAuth2 -> URL Generator -> tick the "bot" field -> tick relevant permissions -> copy the url -> visit it

install

  1. Create and activate virtual env
  2. Install requirements: pip install -r requirements.txt
  3. set env values in trigger.sh
  4. Set up a cronjob (see below)
  5. Test cronjob works
  6. Relax

How it works

We run this on the newcardigan wordpress server.

  1. With a cron job we call trigger.sh
  2. The shell script sets env values then calls send_message.py
  3. The python script checks a custom RSS feed for new cardiparty
  4. If no new post, end
  5. If new post,
    1. save the date of the post to latest_post.txt for the next round of checking
    2. use the values from the RSS feed
    3. publish via API and bot account to Discord

env values

These are all set in trigger.sh, not in crontab, to keep things contained.

We need to include some secrets via environment values:

  • the channel ID (DISCORD_CARDICAST_CHANNEL)
  • the secret bot token for the API call (DISCORD_CARDICAST_TOKEN)
  • the ID of the @cardiCast ping role (DISCORD_CARDICAST_PING)

And because we run python in a virtual environment:

venv - we need to activate the venv using source <path/to/venv>

Cron job command

*/18 * * * * cd /home/cardigan/discord-cardiparty-bot && ./trigger.sh

RSS feed

The rss feed is https://newcardigan.org/category/cardiparties/?feed=featured_image_feed.

This special featured_image_feed is a slightly modified RSS2 feed. The only thing it does differently is include the featured image in an enclosure so that we can pick it up directly from the feed. See the newcardigan WordPress theme for how this works.