Cannot read properties of undefined (reading 'send')

325 views Asked by At

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')

1

There are 1 answers

1
wyndmill On

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`)
});