PUBG tracker script in chat


is there anyway get this script working on discord ?


I have no idea, @IllusionaryOne how different are the script from Discord to Twitch? :slight_smile:


Need to make a copy in Discord and change the $.say(output_string) to $.discord.say(channel, output_string). The channel, you could hard-code for your Discord or come up with a way to make it configurable.


@IllusionaryOne I changed the value still won’t show as it needs to be “registered” as an command in discord. example i change it do $.discord.say(general, output_string) I also tried $.discord.say(channel, output_string). Needs to be coded into a “command” for discord somehow in the script I am not very good with Java.


This uses Rhino (JavaScript) not Java, you would need to look at an existing Discord script to see how we handle and register commands. Unfortunately, I just got back from 2 weeks visiting with in-laws and traveling most of the weekend, I am catching up with work today and cannot walk through how to implement in Discord at this time. My best suggestion really is to look at something simple like scripts/discord/games/8ball.js.


There might be bugs I don’t know how to fix them but so far I got it to work when looking up correct usernames in pubg incorrect names however give me an TypeError: Cannot read property “Rating” from undefined. But I will post what i have so far it does work somewhat. So gives an headstart. Edit: got squad to work @IllusionaryOne looking at 8ball helped little bit.

    (function() {
    function _getJSON(url){
        var HttpRequest =;
        var HashMap =;
        var h = new HashMap();
        h.put('TRN-Api-Key', 'My Key');
        var responseData = HttpRequest.getData(HttpRequest.RequestType.GET, encodeURI(url), '', h);
        return responseData.content;
    function getRanks(json) {
        var stats = json.Stats;
        var results = {};
        for (i in stats) {
            var t = stats[i].Match;
            var r = {};
            lstats = stats[i].Stats
            for (k in lstats) {
                r[lstats[k].label] = lstats[k];
            results[t] = r;
        return results;
    function capitalizeFirstLetter(string) {
        return string.charAt(0).toUpperCase() + string.slice(1);
    $.bind('discordCommand', function(event) {

        var channel = event.getChannel(),
            command = event.getCommand(),
            mention = event.getMention(),
            args = event.getArgs(),
            username = args[0] === undefined ? undefined : String(args[0]),
            statsType = args[1] === undefined ? undefined : String(args[1]),
            allowedTypes = ['solo', 'duo', 'squad'];

        if (command.equalsIgnoreCase('pubg')) {
            // Check arguments

                if (username === undefined || (statsType !== undefined && allowedTypes.indexOf(statsType) === -1)) {
                $.discord.say(channel, $.discord.userPrefix(mention) + 'usage: !pubg <username> [' + allowedTypes.join('|') + ']');

            // Get JSON and parse stats
            var json = JSON.parse(_getJSON("" + username));
            var stats = getRanks(json);

            // Decide which stats types to print
            var displayTypes;
            if (statsType === undefined) {
                displayTypes = allowedTypes;
            } else {
                displayTypes = [statsType];

            // Iterate over stats types and add formatted string to output
            var output = '';
            displayTypes.forEach(function(type) {
                output += capitalizeFirstLetter(type) + ': ' +
                          'Rank #' + stats[type]['Rating']['rank'] +
                          ' with ' + stats[type]['Rating']['displayValue'] + ' points. ';

            $.discord.say(channel, output);
    $.bind('initReady', function() {
        if ($.bot.isModuleEnabled('./custom/pub.js')) {
            $.discord.registerCommand('./custom/pub.js', 'pubg', 6);


There are two conditions that need to be checked.

  1. It looks like if I enter some random name that doesn’t exist, JSON isn’t returned, but HTML:

<div class="alert alert-danger">There was an error loading your profile, admins have been notified! Thanks</div>

  1. You should check the JSON to make sure that it has everything that you want. I do not know the data pattern for PUBG, but I am going to guess that all of the data is not always present in every API call. You should display what is coming back in the JSON and see what is missing that is causing the problem. Perhaps they don’t have solo or duo or squad statistics.


@IllusionaryOne Do you know how to change this to Region EU? or @meJ


I am not aware of how the API works, I simply fixed a couple of bugs once, I do not support this script, unfortunately. That might be something that has to be checked with PUBG.


Hi :slight_smile: I only play on EU and it shows my stats on EU, but how it works, I’m not sure. Try checking the API on


How i can use the pubgtracker api directly with a command pls ? When i use “(customapi$(querystring)&default_region=eu&default_playlist=squad)”, the bot say : No valid channel given.

Sorry for my english.


That question does not relate to the script. Please open a different Support topic.


Below is my version of the pubg stats by default I have it set to Solo EU

Twitch Chat
PhantomBot\scripts\custom\commands\pubgCommand.js (4.9 KB)
PhantomBot\scripts\lang\custom\commands\commands-pubgCommand.js (194 Bytes)

Discord Chat
PhantomBot\scripts\discord\custom\commands\pubgCommand.js (5.1 KB)

Please keep in mind that the discord version uses the new discord from the nightly build so u will have to change discordChannelCommand to discordCommand if your not using the newest nightly build!

EDIT Fixed type and region matching


that spacing was not needed for discord as the \r\n is a new line so why have a space before the new line??? thanks anyways


did it for twitch chat purpose


Does he have the latest newline supporting version of Discord or not? I seem to recall I patched that in recently, but I could be remembering wrong. I think it was even removed at one point from the Nightly and I put it back in. I could be remembering incorrectly though.

I guess what I mean is…

@Ayysir - are you getting newlines in your output or just your spaces?

EDIT: Read your Twitch post, that makes perfect sense where there are no newlines allowed :slight_smile:



well the part you edited was for discord not twitch lol just so you know


the twitch and discord files are both different so thats wierd they use the same settings but the output is totaly different


Remove the \r\n from the twitch version as its useless i forgot i put that in both lol

pubgCommand.js (4.9 KB)


btw the one i edited was the twitch script not the discord one