A Discord moderation bot written in Go. Provides cross-server ban/mute/unmute/extend/warn/infractions features and stores infractions/mute state in MySQL.
- 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
- 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
-
Clone repository
- git clone https://github.com/Lach-dev/Freakbot.git
- cd Freakbot
-
Create a MySQL database
-
Prepare
config.json-
Edit the
config.jsonin the project root. Example (make sure keys match struct tags:discordlowercase,DBuppercase):{ "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.
-
-
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.
- In your application -> Bot settings, enable:
- 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.
-
From PowerShell or CMD:
- Build:
go build -o freakbot.exe . - Run:
.\freakbot.exe - Or run directly:
go run main.go
- Build:
-
In GoLand:
- Create a Run Configuration for
main.go(Packagemain) and run.
- Create a Run Configuration for
On startup the bot:
- Loads
config.json - Calls
infractions.InitDBwhich createsinfractionsandmutestables if missing - Registers slash commands automatically
- DSN format built by code:
user:pass@tcp(host:port)/dbname?parseTime=true&loc=UTC&charset=utf8mb4&multiStatements=true - The
infractionspackage:- Creates tables if missing
- Stores infractions (
infractionstable) - Stores active mutes in
mutestable (JSON list of server IDs + expiry) - Provides functions:
RecordInfraction,StoreMute,GetActiveMute,ExtendMute,RemoveMute,GetExpiredMutes
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
- 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.
- Follow standard Go conventions.
- Add unit tests where appropriate (Guys I don't have any yet, but I'm working on it).