Ralfs Vība

can u make a discord bot that conect with my server and u can check /bal in discord and it displays vault money like that the player has

Kodari AI
KodariSep 6 at 1:03 pm 1
VaultBalanceBot
A Discord bot that connects to a Minecraft server via RCON to display player vault balances. Users can check their in-game money with the /bal command in Discord, which queries the server's Vault economy plugin and returns the player's current balance. The bot supports linking Discord accounts to Minecraft usernames for seamless balance checking.
  • Create a discord.py bot with a /bal <player> slash command.

  • Create a companion Paper plugin that reads the player’s Vault balance through a protected HTTP endpoint.

  • Add configuration, dependency files, and setup instructions for connecting both sides securely.

Created the Discord Vault balance integration.

  • bot.py: Discord bot with /bal <player>.

  • minecraft-plugin: Paper plugin exposing a protected Vault balance endpoint.

  • Shared-secret authentication between the bot and Minecraft server.

  • Added .env.example, requirements.txt, Gradle configuration, plugin config, and setup instructions in README.md.

Run the Minecraft plugin first, configure the shared secret, then install Python dependencies and start the bot with:

Shell
pip install -r requirements.txt
python bot.py

Use /bal Steve in Discord.

Ralfs Vība

so what plugin i need to install in minecraft

Kodari AI
KodariSep 6 at 1:10 pm 1

You need these Minecraft plugins:

  1. Vault — connects plugins to the economy system.

  2. An economy plugin — for example:

    • EssentialsX + EssentialsX Economy

    • CMI

    • The economy plugin you already use

  3. VaultBalanceBridge — the custom plugin included in the project. It connects Minecraft’s Vault balance to the Discord bot.

Install the .jar files in your server’s plugins folder:

Plain Text
plugins/
├── Vault.jar
├── EssentialsX.jar
├── EssentialsXEconomy.jar
└── VaultBalanceBridge.jar

Then:

  1. Start the server once.

  2. Open plugins/VaultBalanceBridge/config.yml.

  3. Set the same secret used by the Discord bot.

  4. Make sure the configured HTTP port is available.

  5. Restart the server.

You do not need a separate Discord plugin in Minecraft. The custom VaultBalanceBridge plugin handles the connection.

Kodari can make mistakes. Review important code before using.
Files
minecraft-plugin
bot.py
README.md
requirements.txt
Code
8 409
minecraft-plugin/src/main/java/com/kodari/vaultbridge/VaultBalanceBridgePlugin.java
package com.kodari.vaultbridge;

import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public final class VaultBalanceBridgePlugin extends JavaPlugin {
    private HttpServer server;
    private ExecutorService executor;
    private Economy economy;
    private String secret;

    @Override
    public void onEnable() {
        saveDefaultConfig();

        RegisteredServiceProvider<Economy> registration =
                getServer().getServicesManager().getRegistration(Economy.class);
        if (registration == null) {
            getLogger().severe("No Vault economy provider is available; disabling.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }

        economy = registration.getProvider();
        secret = getConfig().getString("secret", "").trim();
        if (secret.isEmpty() || secret.equals("change-this-to-a-long-random-secret")) {
            getLogger().severe("Set a unique secret in plugins/VaultBalanceBridge/config.yml; disabling.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }

        try {
            String host = getConfig().getString("host", "127.0.0.1");
            int port = getConfig().getInt("port", 8787);
            server = HttpServer.create(new InetSocketAddress(host, port), 0);
            server.createContext("/balance", new BalanceHandler());
            executor = Executors.newCachedThreadPool();
            server.setExecutor(executor);
            server.start();
            getLogger().info("Balance endpoint listening on " + host + ":" + port);
        } catch (IOException exception) {
            getLogger().log(java.util.logging.Level.SEVERE, "Could not start balance endpoint.", exception);
            getServer().getPluginManager().disablePlugin(this);
        }
    }

    @Override
    public void onDisable() {
        if (server != null) {
            server.stop(1);
        }
        if (executor != null) {
            executor.shutdownNow();
        }
    }

    private final class BalanceHandler implements HttpHandler {
        @Override
        public void handle(HttpExchange exchange) throws IOException {
            try {
                if (!exchange.getRequestMethod().equalsIgnoreCase("GET")) {
                    sendJson(exchange, 405, "{\"error\":\"method_not_allowed\"}");
                    return;
                }

                String providedSecret = exchange.getRequestHeaders().getFirst("X-Bridge-Secret");
                if (providedSecret == null || !MessageDigest.isEqual(
                        secret.getBytes(StandardCharsets.UTF_8),
                        providedSecret.getBytes(StandardCharsets.UTF_8))) {
                    sendJson(exchange, 401, "{\"error\":\"unauthorized\"}");
                    return;
                }

                String playerName = queryParameters(exchange.getRequestURI()).get("player");
                if (playerName == null || !playerName.matches("[A-Za-z0-9_]{3,16}")) {
                    sendJson(exchange, 400, "{\"error\":\"invalid_player\"}");
                    return;
                }

                Future<String> balance = getServer().getScheduler().callSyncMethod(
                        VaultBalanceBridgePlugin.this,
                        () -> lookupBalance(playerName)
                );
                String response = balance.get(5, TimeUnit.SECONDS);
                if (response == null) {
                    sendJson(exchange, 404, "{\"error\":\"account_not_found\"}");
                    return;
                }
                sendJson(exchange, 200, response);
            } catch (InterruptedException exception) {
                Thread.currentThread().interrupt();
                sendJson(exchange, 500, "{\"error\":\"interrupted\"}");
            } catch (ExecutionException | TimeoutException exception) {
                getLogger().warning("Balance lookup failed: " + exception.getMessage());
                sendJson(exchange, 500, "{\"error\":\"lookup_failed\"}");
            } finally {
                exchange.close();
            }
        }
    }

    private String lookupBalance(String playerName) {
        OfflinePlayer player = Bukkit.getOfflinePlayer(playerName);
        if (!economy.hasAccount(player)) {
            return null;
        }

        double balance = economy.getBalance(player);
        return "{\"player\":\"" + escapeJson(playerName)
                + "\",\"balance\":" + balance
                + ",\"formatted\":\"" + escapeJson(economy.format(balance)) + "\"}";
    }

    private void sendJson(HttpExchange exchange, int status, String body) throws IOException {
        byte[] bytes = body.getBytes(StandardCharsets.UTF_8);
        Headers headers = exchange.getResponseHeaders();
        headers.set("Content-Type", "application/json; charset=utf-8");
        headers.set("Cache-Control", "no-store");
        exchange.sendResponseHeaders(status, bytes.length);
        exchange.getResponseBody().write(bytes);
    }

    private Map<String, String> queryParameters(URI uri) {
        Map<String, String> parameters = new HashMap<>();
        String query = uri.getRawQuery();
        if (query == null || query.isEmpty()) {
            return parameters;
        }

        for (String item : query.split("&")) {
            String[] pair = item.split("=", 2);
            if (pair.length == 2) {
                parameters.put(
                        URLDecoder.decode(pair[0], StandardCharsets.UTF_8),
                        URLDecoder.decode(pair[1], StandardCharsets.UTF_8)
                );
            }
        }
        return parameters;
    }

    private String escapeJson(String value) {
        return value.replace("\\", "\\\\").replace("\"", "\\\"");
    }
}