0

So when my bot joins a new server I want it to dm me and say it did but when I try to make it find me by my guild and my id it says undefined

const test = await client.guilds.cache.get('my guilds id').client.users.cache.get("my id").send(yo i joined a new server')

Nick
  • 11
  • 4
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jan 02 '22 at 17:36

1 Answers1

0

You'd want to use the 'guildCreate' event with the cache, like so.

client.on('guildCreate', _ => {
    let you = client.users.cache.get(/* Your User ID */)
    if (you) you.send('Yo, I joined a new server!')
    else console.log(`I can't find you in my cache`)
});
Dharman
  • 30,962
  • 25
  • 85
  • 135
wyndmill
  • 66
  • 6
  • Thanks for the suggestion I had it on guildCreate as the event and I just tried what you said and it cant find me in their cache any other way? – Nick Dec 22 '21 at 22:20