Home > Software design >  I can't send a message to a specific user in discord.js
I can't send a message to a specific user in discord.js

Time:12-28

I'm trying to make a system that sends a user a message when a command is called. But whenever I try, it says TypeError: Cannot read property 'send' of undefined.

Here is the code I am using.

 client.users.cache.get("220683253789163520").send("Test")

I am using discord version 12.

CodePudding user response:

It means the user is not cached, before you need to fetch the user with <Client>.users.fetch method.

Example for your case:

await client.users.fetch('220683253789163520');
client.users.cache.get('220683253789163520').send('Test');

CodePudding user response:

Use Client.users.fetch() to get directly from the API

const user = await client.users.fetch("220683253789163520")
await user.send("Test")
  • Related