Automated bot for posting random XKCD comics to a Discord channel.
- Fetches a random XKCD comic from the official XKCD API.
- Posts the comic as an embedded message in a specified Discord channel.
- Runs automatically on startup.
- Python 3.8+
discord.py
for interacting with Discord.aiohttp
for making asynchronous HTTP requests.
-
Clone the repository:
git clone https://github.com/hazekezia/xkcd_discord_randomizer.git cd xkcd_discord_randomizer
-
Install dependencies:
pip install -r requirements.txt
-
Set up your Discord bot:
- Create a bot on the Discord Developer Portal.
- Enable
MESSAGE CONTENT INTENT
in bot settings. - Copy the bot token.
-
Configure the bot:
- Edit
TOKEN
inmain.py
and replace it with your actual bot token. - Set
CHANNEL_NAME
to the name of the channel where comics should be posted.
- Edit
-
Run the bot:
python main.py
If everything is working correctly, you can automate the comic posting using a cron job. For example, to send an XKCD comic every day at 5 PM, add the following line to your crontab:
0 17 * * * /usr/bin/python3 <your_code_directory>
To edit your crontab, run:
crontab -e
The bot will post messages like this in the specified Discord channel:
Title: "Light Hacks"
https://xkcd.com/1234
- The bot must have
Send Messages
andEmbed Links
permissions in the target channel. - Ensure the bot is in the correct Discord server.
This project is licensed under the MIT License.