Nick
Nick

Reputation: 11

Cannot read properties of undefined (reading 'send')

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

Upvotes: 0

Views: 325

Answers (1)

wyndmill
wyndmill

Reputation: 66

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

Upvotes: 0

Related Questions