0

Im trying to dm a user but I only have there id. This is the code im using:

const member = bot.users.cache.find(ID)
member.send('TEXT')

it isn't working. Does anyone know why?

Toadless
  • 43
  • 5
  • "it isn't working" isn't enough for us to diagnose a problem. What's happening? Are you getting an errors? – Lioness100 Nov 03 '20 at 21:37
  • i get this error i get this TypeError: Cannot read property 'send' of undefined at module.exports (/Users/thomasmcdonald/Documents/Froggit/tickets/createTicket.js:7:52) – Toadless Nov 03 '20 at 21:57
  • Either ID is not a valid snowflake or the user isn't cached. – Lioness100 Nov 03 '20 at 22:27

2 Answers2

1

If the user is not cached you can do this.

const member = bot.users.fetch('user-id',false,true)

That helps to fetch member data directly from API. more at here

Sandeep
  • 545
  • 6
  • 9
0

Like somebody else has stated, the user probably isn't cached. There isn't anything you can do about this as far as I can tell.

If you want to avoid the undefined error your having, and to catch any errors that may occur when sending the message:

const member = bot.users.cache.find(ID);

if (member) member.send('TEXT').catch(console.error);
Ahsoka
  • 149
  • 7