mastersky
mastersky

Reputation: 3

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']
}

Upvotes: 0

Views: 50

Answers (1)

Juan
Juan

Reputation: 26

Did you try using fetch?

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

Upvotes: 1

Related Questions