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

190
Views
Getting Error: "TypeError: Cannot read property 'channels' of undefined"

Here's my code:

module.exports = {
    name: 'suggestions',
    aliases: ['suggest'],
    execute(message, args, cmd, client, discord) {
        let channel = message.guild.channel.cache.find(ch=>ch.id==='890313569260937247')
        if(!channel) return message.channel.send({ content: 'There is no suggestion channel on this Server!' });

        let messageArgs = args.join(' ')
        const embed = new Discord.MessageEmbed()
        .setColor('#008000')
        .setAuthor(message.author.tag)
        .setDescription(messageArgs)
        .setTitle(`${message.author.tag} has a suggestion!!`)

        message.channel.send({ embeds: [embed] })
    }
}

I'm basically creating a command with my command Handler, doing a suggestion command, where the arguments of an user are going to be sent in a MessageEmbed.

If I run the actual command, this error shows up:

TypeError: Cannot read property 'channel' of undefined
    at Object.execute (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\commands\suggestions.js:5:37)
    at module.exports (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\events\guild\message.js:11:25)
    at Client.emit (node:events:394:28)
    at MessageCreateAction.handle (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\node_modules\discord.js\src\client\actions\MessageCreate.js:31:18)
    at Object.module.exports [as MESSAGE_CREATE] (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\node_modules\discord.js\src\client\websocket\WebSocketManager.js:345:31)
    at WebSocketShard.onPacket (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\node_modules\discord.js\src\client\websocket\WebSocketShard.js:443:22)
    at WebSocketShard.onMessage (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\node_modules\discord.js\src\client\websocket\WebSocketShard.js:300:10)
    at WebSocket.onMessage (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\node_modules\discord.js\node_modules\ws\lib\event-target.js:132:16)
    at WebSocket.emit (node:events:394:28)
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

As t.niese said in their comment, Message#guild can be null. If message.guild === null, this means the message was sent in a DM.

Check if the message was sent in a guild first:

if (!message.guild)
  return message.channel.send('This command can only be used in a server!')

const channel = message.guild.channels.get('890313569260937247')
if (!channel)
  return message.channel.send('There is no suggestion channel on this Server!')

Some other points:

  • There is no channel property on Guild; use channels instead.
  • You can use Collection#get to get a channel by its id (no need to use .find(c => c.id === someId).
  • You can use a string directly in send: channel.send('the message') instead of channel.send({ content: 'the message' }).
about 4 years ago · Juan Pablo Isaza Report

0

'channel' is not a property of the Guild class, you probably meant Guild#channels which returns the necessary type of GuildChannelManager.

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!