Skip to content

Lach-dev/Freakbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Freakbot

A Discord moderation bot written in Go. Provides cross-server ban/mute/unmute/extend/warn/infractions features and stores infractions/mute state in MySQL.

Quick overview

  • Language: Go
  • Main functionality: ban, unban, mute, unmute, extend (mute), warn, infractions lookup
  • DB: MySQL (creates required tables automatically on startup)
  • Config file: config.json

Prerequisites (Windows)

  • Go 1.20+ installed and on PATH
  • MySQL server accessible
  • A Discord Bot application with token and appropriate permissions
  • GoLand (optional) — Just what I used

Setup

  1. Clone repository

  2. Create a MySQL database

  3. Prepare config.json

    • Edit the config.json in the project root. Example (make sure keys match struct tags: discord lowercase, DB uppercase):

      {
        "servers": [
          {
            "guild_id": "GUILD_ID_1",
            "muted_role_id": "MUTED_ROLE_ID_1"
          },
          {
            "guild_id": "GUILD_ID_2",
            "muted_role_id": "MUTED_ROLE_ID_2"
          }
        ],
        "DB": {
          "user": "freakbot",
          "password": "your_password",
          "host": "127.0.0.1",
          "port": "3306",
          "database": "freakbot"
        },
        "discord": {
          "srv_channel_id": "MINECRAFT_BRIDGE_CHANNEL_ID",
          "token": "YOUR_DISCORD_BOT_TOKEN"
        }
      }
    • Notes:

      • servers: the list of guilds the bot manages and the role ID to apply for mutes.
      • discord.srv_channel_id: channel ID where Minecraft/remote server commands are sent. (https://modrinth.com/plugin/discordsrv)
      • discord.token: bot token from the Developer Portal.
  4. Enable privileged intents in Discord Developer Portal

    • In your application -> Bot settings, enable:
      • Server Members Intent (GUILD_MEMBERS)
      • Message Content Intent (if needed)
    • Update bot invite with required permissions.

Required bot permissions

  • Manage Roles (for mutes)
  • Ban Members (for ban/unban)
  • View Guild, Send Messages, Manage Messages (as needed)
  • The code sets the session intents to: Guilds, GuildMembers, GuildMessages, MessageContent

Create an invite URL with the appropriate permission integer or give Administrator during development.

Running locally (Windows)

  • From PowerShell or CMD:

    • Build: go build -o freakbot.exe .
    • Run: .\freakbot.exe
    • Or run directly: go run main.go
  • In GoLand:

    • Create a Run Configuration for main.go (Package main) and run.

On startup the bot:

  • Loads config.json
  • Calls infractions.InitDB which creates infractions and mutes tables if missing
  • Registers slash commands automatically

Database details

  • DSN format built by code: user:pass@tcp(host:port)/dbname?parseTime=true&loc=UTC&charset=utf8mb4&multiStatements=true
  • The infractions package:
    • Creates tables if missing
    • Stores infractions (infractions table)
    • Stores active mutes in mutes table (JSON list of server IDs + expiry)
    • Provides functions: RecordInfraction, StoreMute, GetActiveMute, ExtendMute, RemoveMute, GetExpiredMutes

Slash commands and usage

Registered commands (examples):

  • /ban user:<user> reason:<string?> — Ban across configured servers
  • /unban user:<user> reason:<string?> — Unban across configured servers
  • /mute user:<user> duration:<1h|30m|2d|perm> reason:<string?> — Mute across servers
  • /unmute user:<user> — Unmute across servers
  • /extend user:<user> duration:<1h|30m|2d> — Extend existing mute (cannot extend permanent, duh)
  • /warn user:<user> reason:<string?> — Log a warning
  • /infractions user:<user> — Show user's infractions
  • /ping — fun response

Duration formats supported by the bot:

  • Go-style durations: 1h, 30m, 1h30m
  • Days/weeks: 2d, 1w
  • Plain numbers => minutes (e.g., 15 = 15 minutes)
  • Permanent: perm, permanent, inf, infinite, forever

Automations

  • The bot runs a ticker every minute (CheckExpiredMutes) to auto-unmute users whose mute has expired.
  • When a user joins a guild, the bot checks active mutes and reapplies muted role if necessary.

Contributing

  • Follow standard Go conventions.
  • Add unit tests where appropriate (Guys I don't have any yet, but I'm working on it).

About

A Discord moderation bot written in Go.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published