【问题标题】:UnhandledPromiseRejectionWarning: TypeError: Cannot read property of nullUnhandledPromiseRejectionWarning:TypeError:无法读取 null 的属性
【发布时间】:2021-03-27 13:28:27
【问题描述】:
const addReactions = (message, reactions) => {
    message.react(reactions[0])
    reactions.shift()
    if(reactions.length > 0) {
        setTimeout(() => addReactions(message, reactions), 750)
    }
}

module.exports = async (client, id, text, reactions = []) => {
  const channel = await client.channels.fetch(id);

  channel.messages.fetch().then((messages) => {
      if(messages.size === 0) {
          //Send a new messages
        channel.send(text).then(message => {
            addReactions(message, reactions)
        })
    }else{
        //Edit the existing message

      }
  })
}

所以我得到了这个错误:

PS D:\Raketbot> node index.js
(node:7712) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'messages' of null
    at module.exports (D:\Raketbot\first-message.js:13:11)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
etc....

【问题讨论】:

  • 您使用的是什么版本的 discord.js?此代码似乎不适用于较新的版本。
  • 输入catch 看看是什么错误。
  • 一些解释和介绍将有助于我们为您提供帮助

标签: javascript node.js discord.js


【解决方案1】:

问题是您没有从“await client.channels.fetch(id)”接收通道对象。 验证您是否正确调用它。

【讨论】:

    猜你喜欢
    • 2021-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-10
    • 2021-05-20
    • 2021-04-18
    • 2020-11-11
    相关资源
    最近更新 更多