Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!