A Discord bot that automatically sends scheduled messages by reading from a Google Sheet. The bot polls the sheet at regular intervals and sends messages to specified Discord channels when their scheduled time arrives.
- 📅 Schedule Discord messages with specific date and time
- 📊 Manage message queue through Google Sheets
- ⏰ Automatic polling and sending based on configured timezone
- ✅ Track sent messages with timestamps
- 🔄 Configurable polling interval
- 🌍 Timezone-aware scheduling
- Node.js (v14 or higher)
- A Discord bot token
- A Google Cloud Platform project with Sheets API enabled
- A Google Service Account with access to your Google Sheet
- Clone the repository:
git clone <repository-url>
cd discord-messages-scheduler- Install dependencies:
npm install- Create a
.envfile in the root directory with the following variables:
DISCORD_BOT_TOKEN=your_discord_bot_token
GOOGLE_SHEET_ID=your_google_sheet_id
GOOGLE_SERVICE_ACCOUNT_JSON=./service-account.json
SHEET_TAB_NAME=Queue
TIMEZONE=America/Toronto
POLL_SECONDS=60- Place your Google Service Account JSON file in the project root (or path specified in
.env)
Create a Google Sheet with the following columns (case-insensitive):
| send_at | channel_id | message | sent | sent_at |
|---|---|---|---|---|
| 2026-01-05 14:30 | 123456789012345678 | Hello, World! | FALSE | |
| 2026-01-06 10:00 | 123456789012345678 | Scheduled message | FALSE |
- send_at: Schedule time in format
YYYY-MM-DD HH:mm(uses timezone from.env) - channel_id: Discord channel ID where the message will be sent
- message: The message content to send
- sent: Boolean flag (TRUE/FALSE) - automatically updated when message is sent
- sent_at: Timestamp when the message was sent - automatically filled
- Go to the Discord Developer Portal
- Create a new application and add a bot
- Copy the bot token and add it to your
.envfile - Enable the required bot intents (Guilds)
- Invite the bot to your server with appropriate permissions (Send Messages, Read Channels)
Start the bot:
node index.jsThe bot will:
- Connect to Discord
- Begin polling the Google Sheet every
POLL_SECONDSseconds - Send messages when their scheduled time arrives
- Mark messages as sent and record the timestamp
| Variable | Description | Default | Required |
|---|---|---|---|
DISCORD_BOT_TOKEN |
Your Discord bot token | - | ✅ |
GOOGLE_SHEET_ID |
Google Sheet ID from the URL | - | ✅ |
GOOGLE_SERVICE_ACCOUNT_JSON |
Path to service account JSON | - | ✅ |
SHEET_TAB_NAME |
Name of the sheet tab | Queue |
❌ |
TIMEZONE |
Timezone for scheduling | America/Toronto |
❌ |
POLL_SECONDS |
Polling interval in seconds | 60 |
❌ |
- The bot connects to Discord and starts a polling loop
- Every
POLL_SECONDS, it reads all rows from the Google Sheet - For each row where:
sentis not TRUEsend_attime has passed- All required fields are filled
- The bot sends the message to the specified Discord channel
- Updates the row with
sent=TRUEand records the current time insent_at
- discord.js: Discord API wrapper
- googleapis: Google Sheets API client
- luxon: Date/time handling with timezone support
- dotenv: Environment variable management
The bot includes error handling for:
- Invalid date formats in
send_at - Missing or invalid channel IDs
- Missing Google Service Account file
- API failures (logs errors without crashing)
- Messages are only sent once (tracked via the
sentcolumn) - The bot uses the timezone specified in the
.envfile for all time comparisons - Make sure your Google Service Account has edit permissions on the sheet
- The bot needs appropriate Discord permissions to send messages in the target channels
ISC