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

112
Visualizações
Trying to redirect messages from one channel to another one

I am getting this error on the code below:

(node:13760) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of undefined


bot.on('message', async (message) => {
  message
    .delete({ timeout: 10 })
    .catch((err) =>
      logger.error(`Could not delete message (Error: ${err.message})`),
    );

  // Checking if command was executed in report channel
  if (message.channel.name != 'from-user') {
    // Do nothing
    logger.info(
      `message has not been sent in the forwarding channel! Aborting request.`,
    );
  } else {
    if (message.author.bot) return;
    await client.channels.cache.get('910109122572218378').send(message.content);
    console.log(message.content); // log messages
    return;
  }
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If the channel ID is correct, the channel is probably not cached. If you know the channel ID, you could fetch the channel by this ID. If it's cached, it returns the cached channel:

const channel = await client.channels.fetch(CHANNEL_ID)

await channel.send(message.content)
console.log(message.content) // log messages

fetch() returns a Promise, so you'll need to use await.

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