javascriptdiscorddiscord.jsdm

How do I send a DM to a user in discord.js v13


All I'm doing right now is trying to send a dm to myself to see if I can get this working. I've tried:

client.users.cache.get(id).send('hi')
But I'm getting "TypeError: Cannot read properties of undefined (reading 'send')." I suppose this has something to do with myself not being cached, but I'm unsure how to go about caching myself. Does anyone know how to properly do this?


Solution

  • Use UserManager#send(). This will create a dm if needed, then send the message

    client.users.send(userId, "content")