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