Skip to content

aymenelouadi/discord-github-x-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

discord-github-x-bot

A flexible, extensible Discord bot that listens to GitHub webhooks and automatically publishes beautiful release announcements on X (Twitter) โ€” with a Canvas-generated image card.

๐Ÿ“ฆ Features ยท ๐Ÿš€ Quick Start ยท โš™๏ธ Configuration ยท ๐Ÿฆ X Setup ยท ๐ŸŽจ Card Preview ยท ๐Ÿ“ก Adding Repos


โœจ Features

Feature Details
๐Ÿ”— GitHub Webhooks Listens for release and push events โ€” supports unlimited repos
๐ŸŽจ Canvas Image Auto-generates a 1200ร—630 announcement card with logo, name, version & changelog
๐Ÿ–ผ Discord Server Logo Fetched automatically from your Discord guild via bot token
๐Ÿฆ X Auto-Tweet Posts a formatted tweet with the image, no official Twitter API key needed
๐Ÿ“Š Discord Embed Rich branded embed sent to your announcement channel simultaneously
๐Ÿ—„ Deduplication DB JSON database prevents double-posting the same release
๐Ÿงฉ Multi-Repo Monitor multiple GitHub repos, each with different Discord channels & Twitter settings
๐Ÿ” MIT License Fully open source, free to use and extend

๐Ÿ“ Project Structure

discord-github-x-bot/
โ”œโ”€โ”€ index.js                        โ† Entry point โ€” boots all systems
โ”œโ”€โ”€ config.json                     โ† All non-secret configuration
โ”œโ”€โ”€ .env                            โ† ๐Ÿ”’ Secret tokens (never commit!)
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ README.md
โ”‚
โ”œโ”€โ”€ commands/
โ”‚   โ””โ”€โ”€ status.js                   โ† !status Discord command
โ”‚
โ”œโ”€โ”€ database/
โ”‚   โ”œโ”€โ”€ db.js                       โ† JSON database (deduplication)
โ”‚   โ””โ”€โ”€ data.json                   โ† Auto-created at first run
โ”‚
โ”œโ”€โ”€ media/                          โ† Generated PNG announcement cards
โ”‚
โ”œโ”€โ”€ systems/
โ”‚   โ”œโ”€โ”€ discord/
โ”‚   โ”‚   โ”œโ”€โ”€ client.js               โ† Discord.js bot client + guild icon fetcher
โ”‚   โ”‚   โ””โ”€โ”€ canvas.js               โ† ๐ŸŽจ Canvas image generator (1200ร—630)
โ”‚   โ”œโ”€โ”€ github/
โ”‚   โ”‚   โ”œโ”€โ”€ webhook.js              โ† Express server โ€” receives GitHub webhooks
โ”‚   โ”‚   โ””โ”€โ”€ handler.js              โ† Pipeline orchestrator (logo โ†’ canvas โ†’ Discord โ†’ X)
โ”‚   โ””โ”€โ”€ twitter/
โ”‚       โ”œโ”€โ”€ poster.js               โ† X poster via auth_token cookie
โ”‚       โ””โ”€โ”€ formatter.js            โ† Builds beautiful tweet text
โ”‚
โ””โ”€โ”€ utils/
    โ””โ”€โ”€ logger.js                   โ† Colorful timestamped console logger

๐Ÿš€ Quick Start

Prerequisites

  • Node.js v18+ โ€” nodejs.org
  • A Discord bot with Send Messages, Attach Files, Embed Links permissions โ€” Discord Developer Portal
  • A GitHub account with webhook access to your repo(s)
  • An X (Twitter) account you're logged into in your browser

Step 1 โ€” Clone & Install

git clone https://github.com/aymenelouadi/discord-github-x-bot.git
cd discord-github-x-bot
npm install

Windows users: canvas requires native build tools. Run once if needed:

npm install --global --production windows-build-tools

Step 2 โ€” Create your .env file

Create a .env file in the project root:

# โ”€โ”€ Discord โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
DISCORD_TOKEN=your_discord_bot_token_here

# โ”€โ”€ GitHub โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
GITHUB_TOKEN=ghp_your_github_classic_token

# โ”€โ”€ X (Twitter) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
TWITTER_AUTH_TOKEN=your_auth_token_cookie_value
TWITTER_CT0=your_ct0_cookie_value

# โ”€โ”€ Webhook Server โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
WEBHOOK_PORT=3000
WEBHOOK_SECRET=optional_secret_for_hmac_verification

How to get each token: see Discord Token, GitHub Token, and X auth_token sections below.


Step 3 โ€” Configure config.json

Edit the repositories array โ€” add one entry per GitHub repo you want to watch:

{
  "repositories": [
    {
      "id":            "my-awesome-project",
      "enabled":       true,
      "repo":          "github-username/repo-name",
      "events":        ["release", "push"],
      "branch_filter": "main",

      "discord": {
        "guild_id":          "123456789012345678",
        "channel_id":        "987654321098765432",
        "notify_on_push":    false,
        "notify_on_release": true,
        "embed_color":       "#58b9ff"
      },

      "twitter": {
        "enabled":         true,
        "post_on_push":    false,
        "post_on_release": true,
        "hashtags":        ["OpenSource", "GitHub", "JavaScript"]
      },

      "project": {
        "name":              "My Awesome Project",
        "short_description": "A great open-source tool",
        "language":          "JavaScript",
        "logo_source":       "discord_guild"
      }
    }
  ]
}

logo_source: "discord_guild" โ€” the bot fetches your Discord server icon automatically and uses it in the card image.


Step 4 โ€” Set up the GitHub Webhook

In your GitHub repository โ†’ Settings โ†’ Webhooks โ†’ Add webhook:

Field Value
Payload URL https://your-domain.com/github/webhook
Content type application/json
Secret Same value as WEBHOOK_SECRET in .env (optional)
Which events? โ˜‘ Releases ยท โ˜‘ Pushes
Active โœ…

The Payload URL is built from WEBHOOK_PUBLIC_URL (.env) + the path in config.json:

# Example with a real domain:
WEBHOOK_PUBLIC_URL=https://your-domain.com
# โ†’ Payload URL = https://your-domain.com/github/webhook

# Example with localhost (no WEBHOOK_PUBLIC_URL set):
# โ†’ Payload URL = http://localhost:3000/github/webhook

No domain yet? Use ngrok for local testing:

ngrok http 3000
# Then set WEBHOOK_PUBLIC_URL=https://xxxx.ngrok.io

Step 5 โ€” Run

# Production
npm start

# Development (auto-restart on file changes)
npm run dev

You should see:

  โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
  โ•‘   Discord ร— GitHub ร— X Auto-Publisher v1.0  โ•‘
  โ•‘              MIT License  ๐Ÿš€                 โ•‘
  โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

2026-03-13 12:00:00  [DISCORD]  Logged in as YourBot#1234
2026-03-13 12:00:01  [TWITTER]  Authenticated via auth_token cookie โœ“
2026-03-13 12:00:01  [GITHUB ]  Webhook server listening on port 3000
2026-03-13 12:00:01  [GITHUB ]  Endpoint: POST http://localhost:3000/github/webhook
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
2026-03-13 12:00:01  [SUCCESS]  All systems online. Listening for GitHub webhooksโ€ฆ

โš™๏ธ Configuration

Full config.json reference

{
  "webhook_server": {
    "port": 3000,                   // Port the Express server listens on
    "path": "/github/webhook"       // Endpoint path
  },

  "discord": {
    "prefix": "!",                  // Bot command prefix
    "status_message": "Watching GitHub ๐Ÿš€"
  },

  "repositories": [ /* see above */ ],

  "twitter": {
    "tweet_templates": {
      "release": {
        "header": "๐Ÿš€ New Release Drop",
        "footer": "Built with โค๏ธ โ€” Open Source under MIT License",
        "max_changelog_lines": 5    // Max bullet points shown in tweet
      },
      "push": {
        "header": "โšก New Update Pushed",
        "footer": "Stay tuned for more updates!",
        "max_changelog_lines": 3
      }
    }
  },

  "canvas": {
    "width": 1200,
    "height": 630,
    "theme": {
      "bg_gradient_start":  "#0d1117",
      "bg_gradient_end":    "#161b22",
      "accent":             "#58b9ff",
      "accent_secondary":   "#7c3aed",
      "text_primary":       "#f0f6fc",
      "text_secondary":     "#8b949e",
      "logo_glow":          "#58b9ff"
    }
  }
}

๐Ÿค– Discord Token

  1. Go to discord.com/developers/applications
  2. New Application โ†’ give it a name
  3. Bot tab โ†’ Reset Token โ†’ copy the token โ†’ paste as DISCORD_TOKEN in .env
  4. OAuth2 โ†’ URL Generator: scopes bot, permissions: Send Messages, Embed Links, Attach Files
  5. Open the generated URL and invite the bot to your server

๐Ÿ”‘ GitHub Token

  1. Go to github.com/settings/tokens โ†’ Generate new token (classic)
  2. Scopes needed: repo (private repos) or public_repo (public repos only)
  3. Copy and paste as GITHUB_TOKEN in .env

๐Ÿฆ Getting X auth_token

The bot uses browser session cookies โ€” no Twitter Developer API required.

  1. Log in to x.com in your browser
  2. Open DevTools (F12) โ†’ Application tab โ†’ Cookies โ†’ https://x.com
  3. Copy auth_token โ†’ paste as TWITTER_AUTH_TOKEN in .env
  4. Copy ct0 โ†’ paste as TWITTER_CT0 in .env
DevTools โ†’ Application โ†’ Storage โ†’ Cookies โ†’ https://x.com
  auth_token  โ†’  ebb31c...    โ† copy this
  ct0         โ†’  abc123...    โ† copy this too

โš ๏ธ Cookies expire when you log out or after some time. Re-copy them if tweets stop posting. โš ๏ธ Do NOT log out of X while the bot is running.


๐ŸŽจ Tweet Format (Release)

When a new GitHub Release is published, the bot automatically posts:

๐Ÿš€ New Release Drop

๐Ÿ“ฆ My Awesome Project  v2.1.0
๐Ÿ’ฌ A great open-source tool

โœจ What's New:
  โ–ธ Added dark mode support
  โ–ธ 40% performance improvement
  โ–ธ Fixed critical bug in parser
  โ–ธ New CLI interface

๐Ÿ”— https://github.com/owner/repo/releases/tag/v2.1.0

#OpenSource #GitHub #JavaScript

Built with โค๏ธ โ€” Open Source under MIT License

๐Ÿ–ผ Canvas Card Layout

The generated 1200ร—630 PNG card is attached to each tweet and Discord embed:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ† accent line
โ”‚                                                              โ”‚
โ”‚   โ•ญโ”€โ”€โ”€โ”€โ•ฎ   My Awesome Project         [v2.1.0] [JavaScript] โ”‚
โ”‚   โ”‚LOGOโ”‚                                                     โ”‚
โ”‚   โ•ฐโ”€โ”€โ”€โ”€โ•ฏ   A great open-source tool                         โ”‚
โ”‚            โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€         โ”‚
โ”‚            โ–ธ Added dark mode support                         โ”‚
โ”‚            โ–ธ 40% performance improvement                     โ”‚
โ”‚            โ–ธ Fixed critical bug in parser                    โ”‚
โ”‚                                                              โ”‚
โ”‚  โš™ github.com/owner/repo                  ๐Ÿ“„ MIT License   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ† accent line

The logo is circular with a neon glow ring. If no Discord guild icon is found, an auto-generated colored avatar with the project's initial letter is used as fallback.


๐Ÿ“ก Adding More Repositories

No code changes needed โ€” add another object to config.json:

{
  "repositories": [
    { "id": "project-one",   "repo": "you/project-one",   ... },
    { "id": "project-two",   "repo": "you/project-two",   ... },
    { "id": "project-three", "repo": "org/another-repo",  ... }
  ]
}

Each repo can independently configure:

  • Discord channel & embed color
  • Twitter hashtags and on/off per event type
  • Branch filter for push events

๐Ÿ“Š Bot Commands

Command Description
!status Shows monitored repos, total posts, recent releases and bot uptime

๐Ÿ”Œ Health Check

While the bot is running:

GET http://localhost:3000/health

Returns:

{
  "ok": true,
  "uptime": 3600,
  "repositories": ["owner/repo-one", "owner/repo-two"],
  "timestamp": "2026-03-13T12:00:00.000Z"
}

๐Ÿค Contributing

Pull requests are welcome! Open an issue first for major changes.

  1. Fork: github.com/aymenelouadi/discord-github-x-bot
  2. Create your branch: git checkout -b feat/amazing-feature
  3. Commit: git commit -m 'feat: add amazing feature'
  4. Push: git push origin feat/amazing-feature
  5. Open a Pull Request

๐Ÿ“œ License

MIT ยฉ 2026 aymenelouadi


Built with โค๏ธ ยท github.com/aymenelouadi/discord-github-x-bot

About

This bot monitors your GitHub repos and automatically posts updates on X with images

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors