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

145
Vistas
Problems with sending

So, my server has channels for each user, and the name of the channel is their user id.

The way I want it to work is;

When a user DMs the bot with any message, the bot looks for that channel (the channel that's named as their user id) in the server and sends the content of the message it receieved in DMs, but I keep getting an error:

Cannot read property "send" of undefined

Here is my code

client.on("message", async (message) => {
    if (message.channel.type === "dm") {
        if (message.author.bot) return;

        var guild = client.guilds.cache.get("840120593311334410");

        const cha = message.author.id;
        var hsa = await guild.channels.cache.find((ch) => ch.name === cha);
        hsa.send("test");
    }
});
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

There are 2 types of problems I have for you:

  1. The bot does not have the permissions to view the channel or the channel does not exist. (However, you said otherwise in the comments)
  2. You don't have the channel in the cache: The code you use is cache-based, which means you need to make sure you have the channels in the cache. Use a simple GuildChannelManager.fetch() to cache all channels.
 var guild = client.guilds.cache.get("840120593311334410"); const cha = message.author.id; await guild.channels.fetch(); //ONLY NEW LINE var hsa = await guild.channels.cache.find((ch) => ch.name === cha); hsa.send("test");
over 4 years ago · Santiago Trujillo 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