user14659216
user14659216

Reputation:

Discord bot not sending message in default channel when joining the server

Here's the code:

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

I've tried everything

Upvotes: 0

Views: 230

Answers (1)

Nathn
Nathn

Reputation: 429

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}!`)
});

Upvotes: 1

Related Questions