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

185
Visualizações
Why can't my bot get channels? discord.js

I get this error in my console: TypeError: Cannot read property 'channels' of undefined.

The code that is causing the problem:

const channel = guild.channels.cache.find(c => c.type === 'text' && channel.permissionsFor(guild.me).has('SEND_MESSAGES'))

Index.js:

client.on("guildCreate", guild => {
  client.commands.get("joinserver").execute(guild)
});

joinserver.js:

const Discord = require("discord.js")

module.exports = {
  name: 'joinserver',
  description: '',
  execute(message, args, client, guild) {
    const channel = guild.channels.cache.find(c => c.type === 'text' && channel.permissionsFor(guild.me).has('SEND_MESSAGES'))
    const embeds = new Discord.MessageEmbed()
    channel.send(embeds)
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You passing your guild object into the execute function as first parameter (which is not guild but message parameter). So your guild is accessible inside execute function as message right now. You should pass guild into correct argument (4th argument in your example) or change the way how execute function receiving arguments.

client.on("guildCreate", guild => {
  // This should work: you need to pass null to `message`, `args` and `client`
  // because these arguments marked as required
  client.commands.get("joinserver").execute(null, null, null, guild)
});
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