This bot is designed to automatically post messages in a specific Discord channel according to a predefined schedule. It takes messages from Markdown files located in the posts
directory, which are named based on the desired posting date and time. The bot then moves these files to the published
directory after successfully posting.
- Automatically posts messages from a
posts
folder to a Discord channel based on the date and time in the filename. - Files are moved to the
published
directory after they are successfully posted. - Skips files that are older than 3 minutes to ensure only relevant posts are shared.
- Python 3.8+ installed on your system.
- Discord account and a bot token from the Discord Developer Portal.
- The
discord
library.
First, clone the repository to your local machine:
git clone https://github.com/cmd0s/discord-post-scheduler-bot.git
cd discord-post-scheduler-bot
Create a virtual environment to isolate the bot's dependencies:
python -m venv venv
Activate the virtual environment:
- On Windows:
venv\Scripts\activate
- On Linux/macOS:
source venv/bin/activate
Install the required dependencies from requirements.txt
:
pip install -r requirements.txt
- Go to the Discord Developer Portal.
- Click New Application to create a new application and give it a name.
- Navigate to the Bot tab and click Add Bot.
- Copy the TOKEN and save it. This token will be used to authenticate the bot.
(If you cannot find the token, click Reset Token to generate a new one.) - Under Privileged Gateway Intents, enable Message Content Intent.
- Go to the OAuth2 tab and click on URL Generator.
- Select the bot scope.
- Under Bot Permissions, select appropriate permissions, such as Send Messages.
- Copy the generated URL and paste it into your browser to invite the bot to your server.
Replace YOUR_DISCORD_TOKEN
in bot.py
with the token you obtained earlier.
Ensure that the server name (SERVER_NAME
) and channel name (CHANNEL_NAME
) in the script match the server and channel where you want the bot to post.
Run the bot using the following command:
python bot.py
To keep the bot running indefinitely, you can use a screen
session:
screen -S discord_bot
python bot.py
Press Ctrl + A
then D
to detach from the screen session and keep the bot running in the background.
- The bot monitors the
posts
directory for Markdown (.md
) files named using the formatDDMMYYYY-HHMM.md
.DD
- Day of the month.MM
- Month.YYYY
- Year.HHMM
- Time (24-hour format).
- When the date and time in the filename match or are before the current time, the bot posts the content of the file to the specified channel.
- After posting, the bot moves the file to the
published
directory to keep theposts
directory clean. - Files older than 3 minutes that haven't been posted are skipped to avoid outdated messages.
- Place Markdown files in the
posts
directory for the bot to post. - Ensure the filenames are properly formatted (
DDMMYYYY-HHMM.md
), as the bot uses the filename to determine when to post. - The
published
directory stores all the successfully posted messages.
Feel free to customize the bot's settings to match your requirements, such as adjusting the post frequency or adding more features to interact with users on your server.