0

Here's the code:

FUNAI.on('guildCreate', joinedGuild => {
joinedGuild.send(`Hello ${joinedGuild.guild.name}!`) 
});

I've tried everything

  • Does this answer your question? [None of my discord.js guildmember events are emitting, my user caches are basically empty, and my functions are timing out?](https://stackoverflow.com/questions/64559390/none-of-my-discord-js-guildmember-events-are-emitting-my-user-caches-are-basica) – Jakye Nov 19 '20 at 08:55
  • Unfortunately..nope. –  Nov 19 '20 at 09:35
  • you can't just send a message into a guild. You need to define a channel to send it in. Do you not get any error messages? – Worthy Alpaca Nov 19 '20 at 09:38

1 Answers1

1

Your code tries to send a message to a guild/server, which is not possible. However, you can try to send it to the #general channel if it exists (since Discord has removed the default channel function in 2017) :

const getDefaultChannel = (guild) => {
  // Check for a "general" channel, which is often default chat
  const generalChannel = guild.channels.cache.find(channel => channel.name === "general");
  if (generalChannel)
    return generalChannel;
}

FUNAI.on('guildCreate', joinedGuild => {
  var defChannel = getDefaultChannel(joinedGuild);
  console.log(joinedGuild)
  if (defChannel) defChannel.send(`Hello ${joinedGuild.name}!`)
});
Nathn
  • 418
  • 5
  • 17
  • Long not defined. –  Nov 19 '20 at 11:39
  • Sorry, you need to do `npm install long` (on cmd) and then add at the top of your program `var Long = require("long");` to use the code. – Nathn Nov 19 '20 at 13:44
  • it says nothing –  Nov 19 '20 at 17:04
  • I think it has do do with your discord.js version and unfortunatly I can't test them all now, but I edited my answer with a simplified version that get only the #general channel if it exists. It should work with a maximum of versions. – Nathn Nov 19 '20 at 18:24