Discord API error when trying to send one command at discord using JavaScript client

client.user.presence returns a Presence, a very complex object. I believe you are looking for Presence#status, which will return online, offline, idle, or dnd

userinfo.presen = message.client.user.presence.status;

Also, instead of adding every property to the userinfo object after it’s been defined, you could condense your code using object destructuring:

// change:
let userinfo = {};
userinfo.bot = message.client.user.bot;
userinfo.createdat = message.client.user.createdAt;
userinfo.discrim = message.client.user.discriminator;
userinfo.id = message.client.user.id;
userinfo.mfa = message.client.user.mfaEnabled;
userinfo.pre = message.client.user.premium;
userinfo.presen = message.client.user.presence.status;
userinfo.tag = message.client.user.tag;
userinfo.uname = message.client.user.username;
userinfo.verified = message.client.user.verified;
userinfo.avatar = message.client.user.avatarURL;

// to:
const {
 bot,
 createdAt,
 discriminator,
 id,
 mfaEnabled, // if you want to create an alias, you could write `mfaEnabled: alias`
 premium,
 presence: { status },
 tag,
 username,
 verified,
 avatarURL,
} = message.client.user;

console.log(username) // same as `message.client.user.username`, but way shorter!

Show code snippet

Show code snippet

Leave a Comment