owengombas / discord.ts

🤖 Create your discord bot by using TypeScript and decorators!
https://owencalvin.github.io/discord.ts/
324 stars 40 forks source link

On READY event return null for ClientUser property #2

Closed TheLittlePolaris closed 4 years ago

TheLittlePolaris commented 4 years ago

Problem:

on_ready_user_null image When i try to use the "ready" event, the value for user (UserClient) is null and i cannot use any of the ClientUser instance or method.

Expectation:

We should be able to use it the way the native discord.js module do bot.on('ready', () => { bot.user.setActivity(...) })

My workaround solution for now:

workaround_solution

Much appreciate if you can fix it in the near feature :)

Fredi100 commented 4 years ago

Isn't onReady in your case a member of the class you decorated with @Discord. Your own class does not inherit Client. If you want access to the properties of the discord client object, you need to use it this way:

@On('ready')
async onReady(client: Client){
    console.log(client.user);
    // Do stuff with user
}
TheDevMinerTV commented 4 years ago

image Okay, so I have the same issue and for some reason @On('ready') gets called twice.

TheLittlePolaris commented 4 years ago

Isn't onReady in your case a member of the class you decorated with @Discord. Your own class does not inherit Client. If you want access to the properties of the discord client object, you need to use it this way:

@On('ready')
async onReady(client: Client){
    console.log(client.user);
    // Do stuff with user
}

The function is inside a class decorated with @Discord, do i still need to pass in the parameter for Client ?

Fredi100 commented 4 years ago

Yes. @On injects the client object as the last parameter of the function which is why you have to include it. Take a quick look at the Readme

owengombas commented 4 years ago

Yes you have to use the client parameter on the event function :)

Thank's @Fredi100 for the support!