I'm trying to get my discord javascript discord bot to send me a dm using id but it keeps saying:
TypeError: Cannot read property 'send' of undefined.
Any idea?
const Discord = require('discord.js');
const{prefix,token} = require('./config.json');
const bot = new Discord.Client();
bot.once('ready', () => {
console.log(`Ready!`);
});
bot.on('message', message => {
let e = message.content.split(" ");
if(message.content.startsWith(`${prefix}help`))
{
if (message.channel.type == "dm")
{
message.author.send("use !send");
}
}
if(message.content.startsWith(`${prefix}send`))
{
if (message.channel.type == "dm")
{
try{
message.author.send("Message sent");
message.client.users.get("266928832726xxxxxxx").send("someMessage");
}catch(e){console.log("[ERROR]",e)}
}
}
})
bot.login(token);
Okay so what you have to do in order to know what is the problem with send
is, is to at first console.log(message)
and check if you get the value called author
and then check if author
has value or method called send
.
You const your client as bot const bot = new Discord.Client();
And try get members as message.client.users.get("266928832726xxxxxxx")
Message dont have property client.users
so use bot.users.get()
bot.on('message', message => {
let e = message.content.split(" ");
if(message.content.startsWith(`${prefix}help`)){
if (message.channel.type == "dm"){
message.author.send("use !send");
}
}
if(message.content.startsWith(`${prefix}send`)){
if (message.channel.type == "dm"){
message.author.send("Message sent");
bot.users.get("266928832726xxxxxxx").send("someMessage").catch(console.error);
}
}
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.