【问题标题】:TypeError: message.guild.channels.find(...).then is not a functionTypeError: message.guild.channels.find(...).then 不是函数
【发布时间】:2020-04-14 21:13:08
【问题描述】:

这是我从下面的代码中得到的错误:TypeError: message.guild.channels.find(...).then is not a function

        message.guild.channels.find('name', `${message.author.username}-oda`).then(c => {
            channel.overwritePermissions(message.member, {
                CONNECT: true,
                VIEW_CHANNEL: true
            });
            message.channel.send('All Ok.')
        })

【问题讨论】:

  • 您好,您能提供更多上下文并包含更多代码吗? .then 是一个 promise 的方法,所以它很可能与 '.find' 函数没有返回一个 promise。

标签: javascript discord.js


【解决方案1】:

由于您对此答案发表评论说您使用的是 discord.js v11 而不是 v12,因此我正在根据以下tipakA 的评论编辑我的答案。

find 不返回 Promise,因此您不能在其上使用 then

您的解决方案是:

const channel = message.guild.channels.find('name', `${message.author.username}-oda`);
channel.overwritePermissions(message.member, {
                CONNECT: true,
                VIEW_CHANNEL: true
            });
message.channel.send('All Ok.');

【讨论】:

  • 我照你说的做了。它现在给出这样的错误:TypeError: Cannot read property 'find' of undefined
  • @DES 如果您不在 discord.js 的 v12 上,那么该答案不适合您。如果您使用的是 v11,find 不会返回 Promise,因此您不能在其上使用 then
  • discord.js的版本是v11所以能解决吗
  • 他只是告诉你解决方案,我根据tipakA的评论编辑了我的答案,使其更清晰
猜你喜欢
  • 2020-08-26
  • 2021-07-24
  • 1970-01-01
  • 2022-09-28
  • 2020-10-20
  • 2017-06-24
  • 2023-03-28
  • 2021-05-15
  • 1970-01-01
相关资源
最近更新 更多