Login

Discord Thread Scheduler

A simple Pascal-based bot that automatically creates a Discord thread at a scheduled time each week and posts an initial message into it. This is ideal for recurring status updates, weekly meetings, or automated check-ins.

Features

  • Automated Thread Creation: Automatically creates a thread in a specified channel.
  • Scheduled Execution: Fires once a week at a precise day and time.
  • Customizable Messaging: Posts an initial message (supporting mentions) into the newly created thread.
  • Environment-Driven Configuration: All settings are managed via environment variables.
  • Lightweight: Written in Free Pascal, making it efficient and easy to containerize.

Configuration

The application is configured using environment variables. You can use the provided env-example as a template.

Variable Description Example
RUN_AT The schedule in DOW:HH:MM format (1=Sun, 7=Sat). 3:09:00 (Tuesday at 09:00)
DISCORD_BOT_TOKEN Your Discord Bot's authentication token. MTIzNDU2...
DISCORD_CHANNEL_ID The ID of the channel where the thread will be created. 123456789012345678
THREAD_NAME The base name for the thread. The current date is appended automatically. Weekly Status
THREAD_MESSAGE The first message to post in the thread. Supports Discord mentions. @here Please post updates!
ARCHIVE_DURATION (Optional) Minutes until the thread is archived. Defaults to 10080 (7 days). 1440 (1 day)

Schedule Format (RUN_AT)

The RUN_AT variable follows the format DayOfWeek:Hour:Minute:

  • Day of Week: 1 (Sunday) through 7 (Saturday).
  • Hour: 0 through 23.
  • Minute: 0 through 59.

Example: RUN_AT=2:14:30 triggers every Monday at 14:30.

How It Works

  1. Bootstrapping: On startup, the program parses the RUN_AT schedule and validates the environment variables.
  2. Monitoring: It runs a continuous loop, checking the current system time every 10 seconds.
  3. Triggering: When the current day and time match the RUN_AT setting, the "Core" logic is executed.
  4. Execution:
    • Calls the Discord API to create a new thread in the specified channel.
    • The thread name is generated as THREAD_NAME (YYYY-MM-DD).
    • Extracts the new Thread ID from the response.
    • Calls the Discord API again to post the THREAD_MESSAGE inside the new thread.
  5. Cooldown: Once fired, it waits until the next minute to avoid duplicate triggers within the same scheduled minute.

Requirements

  • Runtime: A Discord Bot with Send Messages and Create Public Threads permissions in the target channel.
  • Deployment: Can be run as a standalone binary or via Docker.

Repository

https://git.teletype.hu/tools/statusbot