【问题标题】:Trying to redirect messages from one channel to another one试图将消息从一个渠道重定向到另一个渠道
【发布时间】:2021-11-16 18:48:42
【问题描述】:

我在下面的代码中收到此错误:

(node:13760) UnhandledPromiseRejectionWarning: TypeError: 无法读取 未定义的属性“发送”


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;
  }
});

【问题讨论】:

    标签: javascript discord discord.js


    【解决方案1】:

    如果频道 ID 正确,则频道可能未缓存。如果您知道频道 ID,则可以通过此 ID fetch 频道。如果被缓存,则返回缓存的频道:

    const channel = await client.channels.fetch(CHANNEL_ID)
    
    await channel.send(message.content)
    console.log(message.content) // log messages
    

    fetch() 返回一个 Promise,因此您需要使用 await

    【讨论】:

      猜你喜欢
      • 2015-12-29
      • 2014-10-08
      • 1970-01-01
      • 2020-04-12
      • 2017-07-15
      • 2015-05-29
      • 1970-01-01
      • 2020-10-02
      • 1970-01-01
      相关资源
      最近更新 更多