Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

101
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda