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)
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
Most helpful comment
can you tell me why did i had to use .fetch(), ultimately i had to send the message with this only
i already had the ID though, so user.id is of no use
btw it worked