egebilecen / PZServerDiscordBot

A Project Zomboid Discord Bot written in C# using Discord.NET to manage and execute commands on Project Zomboid Server.
GNU General Public License v3.0
61 stars 11 forks source link
discord-bot discord-dotnet project-zomboid server-management

Project Zomboid Discord Bot for Server Management

Passively Maintained
This bot is written for people to easily manage their Project Zomboid server using Discord. Please check the Installation and Bot Configuration section. Also this bot doesn't support multiple discord servers and only works on Windows operating system. Be sure to have .NET Framework 4.7.2 installed on the machine.

Contents

Features

Installation

Creating the Discord Bot

  1. Go to Applications section of Discord developer portal. (Be sure to login first.)
  2. Click to New Application button on the top right corner of screen.
  3. Enter your Bot's name in pop-up then click to create button. You will be redirected to your application's (bot's) page. In that page, you can update your bot's name, description and even load an image as avatar.
  4. Navigate to Bot section from left menu. Then click to Add Bot button. Then confirm the pop-up. You will be redirected to your bot page.
  5. Click to Reset Token button. Then confirm the pop-up. This will create a new token for your bot. Copy the displayed token and save it in a file. You won't able to view your bot token unless you reset it again. Also do not share this token with anyone. It's basically password of your bot. If you share it with someone else, they will have full control on your bot.
  6. Navigate to OAuth2 section from left menu and select the URL generator from dropdown. Check bot from Scopes section and scroll down to Bot Permissions.
  7. Check the options shown below and copy the generated URL.
  8. Open the copied link on your browser. In the page, select the server (you must be admin on the server otherwise server won't show up but you can always send the link to an admin which they can authorise the bot) that you want bot to work in. Click to Continue button and then to Authorise button. Complete the captcha if it pops-up. Now Bot has joined to your server but it's not running yet.

Installing Bot Files

To complete this step and next step, you must have remote access to your Windows machine.

  1. Navigate to releases and pick a binary version. I would suggest picking the latest version as it would consist new features and bug fixes.
  2. Download the zip archive.
  3. Extract the contents in the archive to the Project Zomboid Dedicated Server folder. Your directory after extraction will look like the image below.
  4. Rename the bat file you were using to start the server as server.bat. For example, if you were using StartServer64.bat, rename it as server.bat.

Writing the Discord Bot Token Into File

  1. Create an empty text file in the directory and name it as bot_token.txt and open it.
  2. Paste the bot token that you saved while creating the discord bot to the first line. (It will look like the picture below.)
  3. Save the file and close it.

Now all you need to do is running PZServerDiscordBot.exe. If you did setup everything correctly, program will automatically run the Discord bot at background and will show the Project Zomboid Server in the console. (Bot may not send the warning messages about the configuration if your discord server's last created channel is not accessable by the bot. You can just type configuration commands regardless.)

Note:
If you never run the project zomboid server before, please run it without using bot. Because when you run the project zomboid server for the first time, it will ask you to setup an admin account. You can't send any key presses to console if you run the server through discord bot's exe file. This also means you can't execute servers commands directly using the console but I did setup all commands in discord bot.

Warning:
If bot doesn't respond to any commands, that could be mean two things:

Bot Configuration

This bot uses 3 different channels to operate. First channel is Public channel where users can interact with bot. Second channel is Command channel where must set to be only visible to server admins. This channel is used for executing server management and bot configuration commands. Third channel is Log channel. There aren't any commands to execute in this channel and it's set for bot to announce stuff. After the bot launched for first time (or not configured), it will ask you to configure the mentioned three channels using !set_command_channel, !set_log_channel and !set_public_channel commands. Those commands are very easy to use. Just reply to any channel with the tag of the channel you want the bot to be configured in. For example: !set_public_channel #bot-public

Bot Configuration Example

Bot Commands

!help command can be used in any of configured 3 channels which bot will respond with the available command list for that channel.

Public Channel

Command Channel

Bot Commands:

Server Commands:

Localization

You can find the default localization file in here. All you need to do is downloading it and translating the all words/sentences in the right side of ":" between two quote marks. Example below will illustrate how it should look like after the translation.

Before translation:

{
  "gen_enab_up": "Enabled",
  "gen_disa_up": "Disabled",
  "gen_hours_text": "hour(s)",
  ...
  "warn_server_not_running": "Server is not running.",
  "warn_bot_conf_not_done": "Bot configuration haven't done yet.",
  ...
}

After translation:

{
  "gen_enab_up": "Aktif",
  "gen_disa_up": "Pasif",
  "gen_hours_text": "saat",
  ...
  "warn_server_not_running": "Server çalışmıyor.",
  "warn_bot_conf_not_done": "Bot ayarları henüz tamamlanmadı.",
  ...
}

Warning: There might be cases where you can see some weird expressions like {log_file}, {current_version}, {state} etc. These are special expressions that will be replaced with related value before displaying the text. Do not translate these. However, you can move them freely in a sentence and match them with your own language's sentence structure.

Some examples of how some of the expressions will look like after the related value replacement:

{day}/{month}/{year} -> 19/12/2022
{year}-{month}-{day} -> 2022-12-19

Bot Version: {version}  -> Bot Version: v1.8.0
Bot Version ({version}) -> Bot Version (v1.8.0)

Server auto start feature has been {state}.      -> Server auto start feature has been enabled.
Non-public mod logging feature has been {state}. -> Non-public mod logging feature has been disabled.

{hours} hours ago -> 10 hours ago
hours ago {hours} -> hours ago 10

After you have completed translating all words/sentences, please create an issue by selecting the Localization Submission template with the title of Localization of <language here> and attaching the translated .json file in a zip archive. I will add it to available localizations. Also, when a new version of the bot released, there might be new added text so it is good to keep an eye on updates. If your current localization is missing the new added text, bot will use the default localization for these.