ThePooN / bancho.js

Interface with Bancho over IRC, made easy and reliable.
https://bancho.js.org
GNU General Public License v3.0
58 stars 6 forks source link

getUserById doesn't return a valid BanchoUser class #28

Closed nzxl101 closed 1 year ago

nzxl101 commented 1 year ago

getUserById() doesn't return a valid class I'm not sure if this is easily fixable since it's dependent on nodesu but it would be nice :)

TypeError: bancho.banchoClient.getUserById(...).sendMessage is not a function

I'm using this workaround for now

let o = await bancho.banchoClient.getUserById(19012828);
bancho.banchoClient.getUser(o.ircUsername).sendMessage("Yo");
ThePooN commented 1 year ago

This snippet is working fine here:

import { BanchoClient } from "bancho.js";

const client = new BanchoClient({
    username: "ThePooN",
    password: "REDACTED",
    apiKey: "REDACTED"
});

client.connect().then(async () => {
    // Send "!stats ThePooN" to BanchoBot
    const user = await client.getUserById(3);
    user.sendMessage("!stats ThePooN");
    console.log(`Sent message to ${user.ircUsername}!`);
});

Upon executing this, I get my stats back from BanchoBot in my own IRC client, indicating that bancho.js successfully sent "!stats ThePooN" to user id 3 (being BanchoBot).

Please post a complete snippet for further assistance

kiwec commented 1 year ago

bancho.banchoClient.getUserById(...).sendMessage is not a function because getUserById(...) returns a promise, not a banchouser object

nzxl101 commented 1 year ago

My bad. I've fixed it with:

(await bancho.banchoClient.getUserById(19012828)).sendMessage("Yo");

Thanks @kiwec Maybe I shouldn't code stuff at 4am. lol