Search code examples
discorddiscord.js

Gametracker Scraper discord.js


So I'm trying to script something that shows how many players are on a Server using gametracker. I found this module. I successfully can log those information in my terminal but i want to display. So when somebody types .info that this information are in the channel.

My Code:


        case 'info':

        const module = require ('gametracker-scraper')

        async function output() {
            let info = await module.get('My Link')
            message.channel.send('Our Server Info:' + info)
        }
            output()

The text that is posted in the Channel when you write .info:


Our Server Info: [object Object]


Other scraper alternatives are welcome!


Solution

  • It is outputting "[object Object]" because you're concatenating a string and an object.

    If you want to output the actual info, you could loop over the object (with, as an example, a for in loop), like this example:

    let infoString = 'Our Server Info:\n';
    for (const element in info) {
        infoString += `${element}: ${info[element]}\n`;
    }
    message.channel.send(infoString);
    

    Which would produce something like this:

    Our Server Info:
    Map: (your map)
    Online: (your player count)
    // etc...