Metin2 Discord bot and webhook alerts for your server
For outage and maintenance messages a webhook is enough. You only need a bot for more than that, and it needs fewer permissions than most people give it.
When the server acts up, most players check Discord first, not your website. For outage and maintenance messages you don't even need a bot, a webhook and a small script are enough.
Channels and roles
Fewer channels are better than many. An empty channel makes the whole server look dead. Something like this is plenty to start with:
- Info (read only):
#rules,#announcements,#patch-notes,#status,#events - Community:
#general,#trading,#guild-recruitment,#screenshots - Support:
#help,#bug-reportsand tickets as private channels - Team (staff only):
#staff,#alerts,#gm-log
Only staff post in Info. Remove "Send Messages" from @everyone in the category permissions and the channels inside inherit it.
Keep roles short too: Admin, GM, Support, Player and an opt in Event Ping role players give themselves. Then you don't have to ping @everyone for every event. People mute servers that ping everyone too often, and after that they miss your maintenance notice as well.
We're stingy with staff permissions. A GM on Discord usually only needs to delete messages and time out members, and Administrator is for whoever actually runs the Discord. What most people forget is the 2FA requirement for moderation in the server's safety settings. With that on, a staff account without 2FA can't ban or delete messages, even if someone stole its password.
Webhooks instead of a bot
A webhook is a secret URL. You send a message to it and Discord posts it in the channel. Create one in the channel settings under "Integrations" and "Webhooks", call it something like "Server status" and copy the URL. It looks like https://discord.com/api/webhooks/<ID>/<TOKEN>.
Sending works with curl, same on FreeBSD and Linux. The body is a small JSON object with a content field:
If it worked, Discord answers with status 204 and an empty body. A message can be up to 2000 characters. No curl on the box? pkg install curl on FreeBSD, apt install curl on Debian and Ubuntu. You can drop this into anything that already runs as a script, like your maintenance script, the nightly backup or the build script that puts out patch notes.
Anyone who has the URL can post in your channel though, links to fake clients included. If it ever leaks, delete the webhook in Discord and make a new one. That's why we keep it in its own file that only root can read: create /root/.discord-webhook with an editor, put nothing but the URL in it, then set the permissions. That keeps it out of your shell history too.
Alert when a core goes down
The script checks whether the ports of your cores still answer and only posts when something changes. The ports are in the CONFIG files of auth and the channels, in the PORT entry. For every outage it reports it drops a marker file, so you get one message when a core goes down and one when it's back, not a new one every minute.
Save it as /usr/local/bin/mt2-status.sh and put your own ports in PORTS:
The PATH line is there because cron starts jobs with a very short search path. On FreeBSD curl lives in /usr/local/bin and wouldn't be found otherwise. nc is part of the FreeBSD base system, on Debian and Ubuntu you get it with apt install netcat-openbsd. Make the script executable and run it once by hand:
If that runs clean, open root's crontab with crontab -e and run it every two minutes:
Before planned maintenance, touch /var/tmp/mt2-maintenance and delete the file afterwards. As long as it's there, the script stays quiet.
On the game server itself the script catches crashed cores, and it can check the db core port that's blocked from outside. But if the whole box goes down, the script goes down with it and nobody hears about it. We'd always run a second copy on another machine, your web server for example, with the game server's public IP in HOST. From outside you only check auth and the channels.
Why a core crashed is in its syserr afterwards, the guide to reading syserr covers that.
What a bot adds
A webhook can only send. A bot stays connected to Discord, reacts to commands and can read data from your server. It opens the connection itself, so you don't open a port for it. Most are written with discord.py or discord.js.
First thing pretty much everyone wants is the player count. Do it as one status message in #status that the bot edits every few minutes. We'd skip channels with the count in their name, Discord strictly limits how often a channel can be renamed. Where the number comes from depends on your files. Some bots count chars whose last_play is within the last few minutes, others ask the cores directly.
Tickets are worth it too. The bot creates a private channel per ticket that only the player and your support can see, and saves a transcript when it's closed. With private messages to single GMs nobody knows later who promised what.
With linked accounts the bot can hand out roles by kingdom or level. We'd only do the linking through Discord login on your website (OAuth2, identify scope), which gives you ID and name but no email and no password. Usually the Discord ID and the game account ID are all you need to store. Players have to be able to unlink at any time, and it belongs in your privacy policy.
Run the bot as its own system user, never as root. If it has a hole, that only gets someone the rights of that one user.
Token and permissions
The token is in the Discord Developer Portal under "Bot". Whoever has it controls the bot with every permission it has. It goes in a file with mode 600 or in an environment variable of the service, never in the source code, never in Git, and not to some helper who offers to host the bot for you. If it leaked anyway, hit "Reset Token" in the Developer Portal and the old one stops working.
The invite link is made there under "OAuth2" with the scopes bot and applications.commands. Tick only what the bot uses. Send Messages is enough for status and alerts, tickets need Manage Channels, role sync needs Manage Roles. No bot needs Administrator. A bot can only assign roles below its own role, by the way. Same with intents: slash commands work without the Message Content intent, role sync needs the Server Members intent.
If the bot reads game data, it gets its own database user. Never root and never the user of the cores. With column level grants it sees only what it needs and never gets near the account table with the passwords:
Column names differ a bit between files, check them first with DESCRIBE player.player;. openssl rand -base64 24 gives you a long password. If the bot has to store something itself, like the account links, it gets its own database that only it writes to:
If the bot runs on another machine, it goes through an SSH tunnel. Don't open the database port for it, the guide on how to secure a Metin2 server explains why.
Spam and fake GMs
The most common scam is a fake GM who DMs players asking for their password or sends them a "new client". Say it plainly in #rules: staff never ask for passwords, never send files by DM, and downloads only come from your website. Give staff roles their own colour and show them separately in the member list, then everyone can see who's really on the team.
For spam accounts, what Discord has built in is usually enough. At verification level Medium an account has to be registered on Discord for at least 5 minutes before it can post, at High it also has to be on your server for 10 minutes. In AutoMod, add rules for scam phrases and for links that don't point to your own domain. On launch day, slowmode in #general and #trading helps.
Also, a Discord ban is not a game ban. Decide up front whether you link the two.
Discord alerts with Servergilde
The monitoring from Servergilde is free and posts crashed cores, channels that went down and the all clear to your channel through a webhook, by email too if you like. All it needs is the agent for FreeBSD and Linux, which never sends passwords or database contents. The free server check comes with it.
The Discord bot for status and tickets and the Discord bot with account linking are modules still being built, you can reserve them on their pages. You can sign up and set up the alerts today.
Frequently asked questions
How do I post to a Discord channel with curl?
content field to it, same on FreeBSD and Linux: curl -H "Content-Type: application/json" -d '{"content": "Maintenance at 6 pm"}' "WEBHOOK-URL". Discord answers with status 204 if it worked. A message can be up to 2000 characters.How do I get a Discord alert when my Metin2 server crashes?
nc -z and posts to a webhook when one stops answering. It only reports changes, so you get one message when a core goes down and one when it's back. To catch the whole machine going down, run a second copy on another server.Does a Discord bot need administrator permissions?
How do I stop fake GMs scamming players on my Discord?
#rules that staff never ask for passwords, never send files by DM and that downloads only come from your website. Give staff roles their own colour and show them separately in the member list, so players can see who really is on the team. AutoMod rules for scam phrases and for links to other domains help too.