Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Discordjs bot error what's my mistake? cannot read property 'send' of undefined

It seems that the code is normal, but it displays cannot read property send of undefined in the console, despite the fact that in the console output it is clearly defined. Args is registered in index.js

const Discord = require('discord.js');
const data = require('quick.db');
const settings = require('../settings.json')

exports.run = async(client, message, args) => { 
var rcv = args[0];
var msg = args.slice(1).join(' ');
var sender = message.author;
console.log(rcv + ' ' +msg)

client.users.cache.get(rcv).send(msg);


}

exports.help = {
  name: 'private',
  aliases: ['private', 'pmsg']
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Did you try using fetch?

const user = await client.users.fetch(rcv);
user.send(msg);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading