Skip to content

News‐Bot

b1tk1ll3r edited this page Aug 15, 2025 · 2 revisions

📢 News Bot – Overview & Workflow

The News Bot allows curated messages to be delivered via direct messages (DMs) to subscribed users.
Users must actively opt in to receive messages. Server admins can also add recipients directly.


🚀 How It Works

1. Installation & Permissions

  • Bot User with the following OAuth2 scopes:
    • bot
    • applications.commands
  • Required server permissions:
    • View Channels
    • Send Messages (only for welcome posts / informational messages)
  • Privileged Gateway Intents: not required
    → No message content or full member list collection.

2. User Opt-in

There are two ways to add users to the distribution list:

a) Slash Command /subscribe

  • User runs /subscribe.
  • Bot stores the user ID and optionally the display name in a SQLite database.
  • Optional: immediate welcome DM.

b) User Context Command (Admins only)

  • Admin right-clicks a user in the member list → Apps“Add to recipients”.
  • Bot checks whether the executing user has admin/mod rights (Administrator or Manage Guild).
  • If allowed: target user ID is stored in the database.

3. Opt-out

  • Slash command /unsubscribe
  • Removes the user from the recipient list.
  • Confirmation sent as an ephemeral message.

4. Storage (SQLite)

Table: subscribers

  • user_id (PRIMARY KEY)
  • username
  • added_at (timestamp of subscription)

5. Message Delivery

a) Single DM

  • Through the web interface, send a message to a single user ID.

b) Bulk DM

  • Send a message to all stored subscribers.
  • A delay (~1.2 s) is added between sends to avoid hitting rate limits.
  • Displays a summary of successful and failed deliveries.

6. Privacy & Security

  • Only admins can add other users (via user context command).
  • Every user must actively opt in or be added by an admin.
  • Users can opt out anytime with /unsubscribe.
  • No message content is stored — only user IDs, usernames, and subscription date.
  • Bot does not require any privileged gateway intents.

⚙️ Technical Details

Main Components

  • discordgo – Discord API client
  • modernc.org/sqlite – SQLite driver without CGO
  • net/http – Web interface

Command Types

  • /subscribe & /unsubscribe: ChatApplicationCommand
  • Add to recipients: UserApplicationCommand (visible to admins only)

Example Flow (User Context Command)

sequenceDiagram
    participant Admin
    participant Discord
    participant Bot
    Admin->>Discord: Right-click user → Apps → "Add to recipients"
    Discord->>Bot: InteractionCreate Event
    Bot->>Bot: Check admin permissions
    Bot->>SQLite: Save user ID + username
    Bot-->>Admin: Ephemeral confirmation
Loading