I'm having a weird issue while following this tutorial. Building a JS Discord bot, literally only 33 lines in and its throwing errors about .send being undefined. I've googled around and I can't find anything that has helped get any closer to working this out.
const fs = require("fs");
const Discord = require("discord.js");
const client = new Discord.Client();
const config = require("./config.json");
client.login(config.token);
client.on("ready", () => {
client.user.setGame(`on ${client.guilds.size} servers`);
console.log(`Ready to serve on ${client.guilds.size} servers, for ${client.users.size} users.`);
});
client.on("guildMemberAdd", (member) => {
console.log(`New User ${member.user.username} has joined ${member.guild.name}` );
member.guild.defaultChannel.send(`${member.user} has joined this server`);
});
client.on("message", (message) => {
if (!message.content.startsWith(config.prefix) || message.author.bot) return;
if (message.content.startsWith(config.prefix + "ping")) {
message.channel.send("pong!");
} else
if (message.content.startsWith(config.prefix + "foo")) {
message.channel.send("bar!");
}
});
client.on("error", (e) => console.error(e));
client.on("warn", (e) => console.warn(e));
client.on("debug", (e) => console.info(e));
When ran, the console.log works without fuss, but the message to default channel throws the following error in PowerShell
C:\Users\super\Desktop\autoslap\mybot.js:18
member.guild.defaultChannel.send(`${member.user} has joined this server`);
^
TypeError: Cannot read property 'send' of undefined
Any help would be appreciated, getting frustrated over what is probably something so simple.