Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

388
Visualizações
Cannot read properties of undefined (reading 'channels')

I'm trying to make an event that when someone added my bot it will send a message embed on a channel that my bot can send the message embed.

discord.js: v13.6.0

Node: v17.7.2

events/guildCreate.js

const client = require("../index");
const discord = require("discord.js")

client.on("guildCreate", async (client, guild) => {
  let channel = guild.channels.cache.find(
    channel =>
      channel.type === "text" &&
      channel.permissionsFor(guild.me).has("SEND_MESSAGES")
  );
  channel.send( new discord.MessageEmbed()
               .setDescription("**Thank you for adding me!**")
               .setColor("#fcba03"))
})

edit: I kinda of fix my problem with the reading channels:

const client = require("../index");
const { MessageEmbed } = require("discord.js")

client.on("guildCreate", async (guild, message) => {
  let channel = guild.channels.cache.find(
    channel =>
      channel.type === "text" &&
      channel.permissionsFor(guild.me).has("SEND_MESSAGES")
  );
  const embed = new MessageEmbed()
  embed.setDescription("Thank you for adding me!")
  embed.setColor("#2f3136")
  message.guild.channels.cache.get(channel).send(embed)
})

but then again got new error: TypeError: Cannot read properties of undefined (reading 'guild')

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think your “channel” is an array instead of a channel object, because you're filtering all text channels. Make sure to select the first channel of the array/collection.

Try to show what shows up when you log the “channel”

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda