Discord.js: bot.users.cache.get('id') returns undefined

Created on 9 Aug 2020  路  5Comments  路  Source: discordjs/discord.js

vote.user - 457556815345877003
code -

try {
        await bot.users.cache.get(vote.user).send(`${dailyMoney} Credits Has Been Added To Your Balance!`);
} catch (error) {
console.error(error);
}

vote.user is my Discord ID.
can anyone tell me why did it return undefined?
i am pretty sure vote.user is not an empty string

the object data i get from top.gg whenever someone votes my bot

{ 
bot: '694191215062679604',
user: '457556815345877003',
type: 'test',
query: [Object: null prototype] { test: 'data', notRandomNumber: '8' },
isWeekend: true
}

The Error -

TypeError: Cannot read property 'send' of undefined
at DBLWebhook.<anonymous> (/home/container/index.js:141:45)
unverified bug

Most helpful comment

can you tell me why did i had to use .fetch(), ultimately i had to send the message with this only

try {
        let user = await bot.users.fetch(vote.user);
        await bot.users.cache.get(user.id).send(`${dailyMoney} Credits Has Been Added To Your Balance!`);
} catch (error) {
        console.error(error);
}

i already had the ID though, so user.id is of no use

btw it worked

All 5 comments

It means that the user is uncached. Try fetching it with <Client>.users.fetch(<ID>)

okay

how am i suppose to send a message?
fetch returns this

User {
id: '457556815345877003',
bot: false,
username: 'Firez',
discriminator: '6969',
avatar: 'a_3772fca30f6d6bf2480b2f19568d112d',
flags: UserFlags { bitfield: 64 },
lastMessageID: null,
lastMessageChannelID: null
}

That's normal, it works. Ask further help on the Discord.js server

can you tell me why did i had to use .fetch(), ultimately i had to send the message with this only

try {
        let user = await bot.users.fetch(vote.user);
        await bot.users.cache.get(user.id).send(`${dailyMoney} Credits Has Been Added To Your Balance!`);
} catch (error) {
        console.error(error);
}

i already had the ID though, so user.id is of no use

btw it worked

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Alipoodle picture Alipoodle  路  3Comments

Dmitry221060 picture Dmitry221060  路  3Comments

PassTheMayo picture PassTheMayo  路  3Comments

smchase picture smchase  路  3Comments

Blumlaut picture Blumlaut  路  3Comments