Skip to content

ManuelReschke/discord-image-uploader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Discord Image Uploader

A Go tool that automatically uploads images from specific folders on your PC to a Discord channel.

Latest Release Go Version License Downloads

📥 Download

Download the latest version for your operating system from the Releases page.

💡 Tip: After downloading, make the file executable:

chmod +x discord-image-uploader-*

🚀 Quick Start

  1. Download binary (see above)
  2. Create configuration:
    curl -O https://raw.githubusercontent.com/ManuelReschke/discord-image-uploader/main/config/config.example.json
    mv config.example.json config.json
  3. Create Discord webhook and add URL to config.json
  4. Start:
    ./discord-image-uploader-* -config config.json

Features

  • Multi-Path Monitoring: Watch multiple configurable folders for new image files in real-time
  • Recursive/Non-Recursive: Each path can be individually monitored recursively or top-level only
  • Exclude Patterns: Exclude folders/files per path (e.g., "Thumbs", "*.tmp", ".git")
  • Discord Integration: Automatic upload to Discord channel via Bot API or Webhooks
  • Supported Formats: PNG, JPG, JPEG, GIF, WEBP
  • Batch Upload: Upload multiple images simultaneously
  • Configurable: Upload intervals, batch size, file size limits
  • Optional: Delete images after successful upload
  • Robust Error Handling: Comprehensive logging and graceful shutdown
  • Windows Pause: Window stays open on errors for better user experience
  • Backward Compatibility: Old configurations continue to work
  • File Size Validation: Discord-compliant size limits (8MB default)

Installation

Prerequisites

  • Go 1.19 or higher
  • Option 1: Discord Bot Token and appropriate permissions
  • Option 2: Discord Webhook URL (easier setup)

Setup

  1. Clone repository:

    git clone https://github.com/ManuelReschke/discord-image-uploader.git
    cd discord-image-uploader
  2. Install dependencies:

    go mod tidy
  3. Create configuration:

    cp config/config.example.json config/config.json
  4. Configure Discord (choose one option):

    Option A: Webhook (Recommended - Easier Setup)

    • Go to your Discord channel
    • Right-click → "Edit Channel" → "Integrations" → "Webhooks"
    • Click "New Webhook" and copy the webhook URL
    • Enter the webhook URL in config/config.json

    Option B: Discord Bot

    • Create a Discord Bot at https://discord.com/developers/applications
    • Copy the Bot Token
    • Invite the bot to your server with "Send Messages" and "Attach Files" permissions
    • Find the Channel ID of the target channel
    • Enter token and Channel ID in config/config.json
  5. Compile tool:

    go build -o discord-image-uploader.exe ./cmd

Configuration

Configuration is done via a JSON file (config/config.json):

Multi-Path Configuration (v0.2.0+):

{
  "discord": {
    "webhook_url": "https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_WEBHOOK_TOKEN"
  },
  "watcher": {
    "paths": [
      {
        "path": "C:\\Users\\Username\\Pictures\\Screenshots",
        "recursive": true,
        "exclude_patterns": ["Thumbs", "*.tmp", ".git"]
      },
      {
        "path": "C:\\Users\\Username\\Downloads\\Images",
        "recursive": false,
        "exclude_patterns": ["temp", "cache"]
      }
    ],
    "supported_formats": [".png", ".jpg", ".jpeg", ".gif", ".webp"],
    "delete_after_upload": false
  },
  "upload": {
    "batch_size": 5,
    "interval_seconds": 10,
    "max_file_size_mb": 8
  }
}

Legacy Configuration (still supported):

{
  "discord": {
    "webhook_url": "https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_WEBHOOK_TOKEN"
  },
  "watcher": {
    "folder_path": "C:\\Users\\Username\\Pictures\\Screenshots",
    "supported_formats": [".png", ".jpg", ".jpeg", ".gif", ".webp"],
    "delete_after_upload": false
  }
}

Configuration Options

Discord Configuration

Parameter Description Required Default
discord.webhook_url Discord Webhook URL (Option A) Webhook or Bot -
discord.token Discord Bot Token (Option B) Webhook or Bot -
discord.channel_id Discord Channel ID (Bot only) With Bot Token -

Watcher Configuration

Parameter Description Default
watcher.paths Array of watch paths (v0.2.0+) -
watcher.paths[].path Path to watch -
watcher.paths[].recursive Watch recursively (true/false) true
watcher.paths[].exclude_patterns Exclude pattern array []
watcher.folder_path Legacy: Single path (deprecated) -
watcher.supported_formats Supported file formats [".png", ".jpg", ".jpeg", ".gif", ".webp"]
watcher.delete_after_upload Delete files after upload false

Upload Configuration

Parameter Description Default
upload.batch_size Number of files per batch 5
upload.interval_seconds Upload interval in seconds 10
upload.max_file_size_mb Maximum file size in MB 8

Exclude Pattern Examples

  • "Thumbs" - Excludes all folders named "Thumbs"
  • "*.tmp" - Excludes all .tmp files
  • ".git" - Excludes .git folders
  • "cache" - Excludes folders named "cache"

Usage

./discord-image-uploader.exe -config config/config.json

Command Line Options

  • -config: Path to configuration file (default: config/config.json)

Environment Variables

Configuration values can also be set via environment variables:

# Webhook configuration
export DISCORD_UPLOADER_DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/..."

# Bot configuration (alternative)
export DISCORD_UPLOADER_DISCORD_TOKEN="your_token"
export DISCORD_UPLOADER_DISCORD_CHANNEL_ID="your_channel_id"

# Additional options
export DISCORD_UPLOADER_WATCHER_FOLDER_PATH="/path/to/watch"

Project Structure

discord-image-uploader/
├── cmd/
│   └── main.go                 # Main application
├── internal/
│   ├── config/
│   │   └── config.go          # Configuration management
│   ├── discord/
│   │   └── client.go          # Discord API Client
│   ├── watcher/
│   │   └── watcher.go         # File System Watcher
│   └── uploader/
│       └── uploader.go        # Upload logic
├── config/
│   └── config.example.json    # Example configuration
├── go.mod
├── go.sum
└── README.md

How It Works

  1. Initialization: Loads configuration and establishes Discord connection (Bot or Webhook)
  2. Folder Monitoring: Watches configured folder with fsnotify
  3. File Detection: Detects new image files in supported formats
  4. Queue: Adds files to upload queue
  5. Batch Upload: Uploads files via Discord API (Bot) or HTTP requests (Webhook)
  6. Cleanup: Optional: Deletes files after successful upload

Webhook vs. Bot

Aspect Webhook Bot
Setup Very easy - just copy URL Complex - create bot, set permissions
Permissions Automatically available Manual configuration
Rate Limits Less restrictive Discord Bot Rate Limits
Features File upload only Extended Discord features possible
Recommendation ✅ For simple uploads For advanced bot functions

Development

Dependencies

Build

Use the Makefile for easy builds:

# All platforms
make build-all

# Current platform only  
make build

# Development build
make dev

# Full release
make release

# Show help
make help

Manual Builds:

# Development build
go build -o discord-image-uploader ./cmd

# Cross-platform builds
make build-windows  # Windows builds
make build-linux    # Linux builds  
make build-mac      # macOS builds

Tests (planned)

go test ./...

Troubleshooting

Common Issues

  1. "Failed to connect to Discord"

    • With Webhook: Check webhook URL for validity
    • With Bot: Check bot token and channel ID, ensure bot has necessary permissions
  2. "Watch path does not exist"

    • Check the path in configuration
    • Ensure the folder exists
  3. "File too large"

    • Standard Discord limit is 8MB
    • Nitro servers have 50MB limit

Logging

The tool logs all important events:

  • Connection status
  • File detection
  • Upload status
  • Errors and warnings

License

MIT License - see LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Roadmap

  • Image compression before upload
  • Web interface for configuration
  • Multiple Discord server support
  • Statistics and monitoring
  • Plugin system for various cloud providers

About

Upload automatically images from your machine to a discord channel via webhook.

Resources

License

Stars

Watchers

Forks

Packages

No packages published