User being displayed as [object Object]
Hey, I'm trying to display a leaderboard of users having the most gold saved in my sqlite database, here's my command:
Works fine with
user.global_name
but displaying just the user
results in [object Object]
in the message. Why is that? I thought that printing out user in the string literal or using .toString()
method will automatically display the user as mention @username
. What am I missing?5 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!<User>.toString()
returns '<@id>'
, where User
is a discord.js class instanse (structure). Your fetchUser
function returns a raw object, not the User
class instanse.Thanks @syjalo. Is there a way to convert such object into user class instance? Or can I fetch the user in a different way to get the user class instance?
The
User
class doesn't has .globalName
property yet. And you can just do
let me try!
Works like charm, thanks a lot! :)