I'm just following a tutorial to get the basics of this down but I've run into an issue that is probably super simple but both myself and my brother who has a functional bot he made can't work out whats wrong here. When I run it the console.log functions properly but then it crashes out.
The code is below
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));
Everything should be up to date, I only set things up last night.
if you need help with discord.js installation or usage, please go to the discord.js Discord server instead:
https://discord.gg/bRCvFy9
This issue tracker is only for bug reports and enhancement suggestions. You won't receive any basic help here. why didn't you read that and instead just ignored and deleted that 馃
This was the closest thing I could find, couldn't even find that Discord server despite looking for it. Thanks.
The issue is that defaultChannel is a deprecated param. Newer guilds don't have a defaultChannel by default, and old guilds can delete the channel. This is due to Discord's new API change. Hence your error.
~If you need it, you can use this polyfill, replacing any usage of defaultChannel with newDefaultChannel (or whatever you may want to name it).
Note that this polyfill may only work in Discord.js 12.0, unless you replace VIEW_CHANNEL with READ_MESSAGES~
My bad, I'll have to look for a better code for myself then.. ~Man, today was just horrible~
just to be 100% clear, that code above is bad, and you should not use it
@Slappybruh 
Most helpful comment
This was the closest thing I could find, couldn't even find that Discord server despite looking for it. Thanks.