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

99
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");
    }
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There are 2 types of problems I have for you:

  1. The bot doesn’t have the permissions to see the channel, or the channel doesn’t exist. (You said otherwise in comments however)
  2. You do not have the channel in the cache - The code you use relies on cache which means you have to make sure you have the channels cached. Use a simple GuildChannelManager.fetch() to cache all the 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");
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