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.pyfor interacting with Discord.aiohttpfor 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 INTENTin bot settings. - Copy the bot token.
-
Configure the bot:
- Edit
TOKENinmain.pyand replace it with your actual bot token. - Set
CHANNEL_NAMEto 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 -eThe bot will post messages like this in the specified Discord channel:
Title: "Light Hacks"
https://xkcd.com/1234
- The bot must have
Send MessagesandEmbed Linkspermissions in the target channel. - Ensure the bot is in the correct Discord server.
This project is licensed under the MIT License.
