Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
Can't send a message to a specific channel

I'm trying to create a modmail system and whenever I try to make it, it says "channel.send is not a function, here is my code."

const Discord = require("discord.js")
const client = new Discord.Client()
const db = require('quick.db')
// ...
client.on('message', message => {
  if(db.fetch(`ticket-${message.author.id}`)){
    if(message.channel.type == "dm"){
      const channel = client.channels.cache.get(id => id.name == `ticket-${message.author.id}`)
      channel.send(message.content)
    }
  }
})
// ...
client.login("MYTOKEN")

I'm trying this with version 12.0.0

EDIT: I found my issue, for some reason the saved ID is the bots ID, not my ID

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

As MrMythical said, you should use the find function instead of get. I believe the issue is that you're grabbing a non-text channel, since channel is defined, you just can't send anything to it.

You could fix this by adding an additional catch to ensure you are getting a text channel, and not a category or voice channel. I would also return (or do an error message of sorts) if channel is undefined.

Discord.js v12:

const channel = client.channels.cache.find(c => c.name === `ticket-${message.author.id}` && c.type === 'text');

Discord.js v13:

const channel = client.channels.cache.find(c => c.name === `ticket-${message.author.id}` && c.type === 'GUILD_TEXT');

Edit: You can tell channel is defined because if it weren't it would say something along the lines of: Cannot read property 'send' of undefined.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You are trying to find it with a function. Use .find for that instead:

const channel = client.channels.cache.find(id => id.name == `ticket-${message.author.id}`)
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda