Jump to content


Photo

Trying to integrate node-steam-user with a discord bot

node.js node-steam-user

  • Please log in to reply
3 replies to this topic

#1 azz_man

azz_man

    Newbie

  • Member
  • Pip
  • 2 posts

Posted 04 June 2019 - 12:46 AM

So I want to create a very simple discord bot. I already have it running except I cannot figure out how to integrate this library properly. I want the bot to simply retrieve the amount of players on a certain steam game and then return the amount of players. Here's my code so far:

 

const SteamUser = require('./node-steam-user-master/index.js');
var user = new SteamUser();

user.login({
"accountName": "",
"password": ""
});

user.on('loggedOn', function(details){
console.log(user.steamID);
})

 

I will also note I have been getting an error when I try to run this code (I do have the accountName and password fields filled in on my actual program) This is the error I get: 

----------------------------------------------------------------------------------------------------------------------

internal/modules/cjs/loader.js:638

    throw err;
    ^
 
Error: Cannot find module '@doctormckay/stats-reporter'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:690:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (D:\Discord_Code\bot\node-steam-user-master\index.js:1:1)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
----------------------------------------------------------------------------------------------------------------------
 
So that's my first problem, but the other is how do I use the getPlayerCount Method? I'm assuming I need to use a different constructor because the SteamUser doesn't seem to have that method available.
 
Any help would be appreciated, thanks.
 


#2 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 2,137 posts

Posted 04 June 2019 - 04:54 PM

You're welcome to use the module by downloading it from Github, but that's ill-advised. You should be using npm install steam-user on the command line to download the library. But if you really really want to download from Github, you'll need to run npm install inside the module directory to download dependencies.

 

Once you're logged on, you should be able to use user.getPlayerCount(...)



#3 azz_man

azz_man

    Newbie

  • Member
  • Pip
  • 2 posts

Posted 05 June 2019 - 11:00 PM

Ok that helped and made a lot more sense. So I am now able to use the command however it is not returning the player count. I'm positive it's because I'm not using the method correctly as I'm not sure what to put for the second parameter. Right now I have this: 

const SteamUser = require('steam-user');
var user = new SteamUser();

user.logOn();
console.log(user.getPlayerCount(504370,30));

and when I print the player count I get this as a result: 

 

Promise { <pending> }

 

I also tried to do:

var count = Promise.resolve(user.getPlayerCount(504370,[]))
console.log(count);

 

however this still just prints:

Promise { <pending> }

 

Any idea what I'm doing wrong, I'm sure it's a lot as I'm very new to this.



#4 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 2,137 posts

Posted 05 June 2019 - 11:07 PM

getPlayerCount is an asynchronous method. You need to either handle the Promise, or attach a callback (user.getPlayerCount(504370, function(err, count) { ... })).

 

But you also need to wait for the loggedOn event before you do anything after calling logOn.







Also tagged with one or more of these keywords: node.js, node-steam-user

2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users