【问题标题】:client.catch is not a function and role keeps making "new role" instead of name I specify?client.catch 不是一个函数,并且角色不断制作“新角色”而不是我指定的名称?
【发布时间】:2019-06-30 13:04:00
【问题描述】:

我可能只是遗漏了一些简单的东西,但我以前从未遇到过此错误,而且我认为我对其进行的编辑不足以导致此问题,因为它是最后一个功能。下面的代码块一直在文件顶部给我这个错误:

(node:17592) UnhandledPromiseRejectionWarning: TypeError: client.catch is not a function

我已指定client = new Discord.Client();

我遇到的另一个问题是,在目标接受了由挑战者。它只是创建了一个名为“新角色”的角色。对这些问题有任何帮助吗?

if (message.channel.id === '541736552582086656') return challenged.send("Do you accept the challenge? Please reply with 'accept' or 'deny'.")
  .then((newmsg) => {
    newmsg.channel.awaitMessages(response => response.content, {
      max: 1,
      time: 150000,
      errors: ['time'],
    }).then((collected) => {
        // Grabs the first (and only) message from the collection.
        const reply = collected.first();

        if (reply.content === 'accept'){
          reply.channel.send(`You have ***accepted *** the challenge from ${challenger}. Please wait while your battlefield is made...`);
          message.author.send(`${target} has accepted your challenge! Please wait while the channel is made for your brawl...`)
            var server = message.guild;
            var permsName = `${target} vs ${challenger}`;
            var name = `${target} vs ${challenger}`;
            message.guild.createRole({
                data: {
                    name: permsName,
                    hoist: true,
                    color: "#00fffa",
                    permissions: [] }
            }).then(role => {
                target.addRole(data, permsName)
                challenger.addRole(role, permsName)


                // client.catch error occurring below
                .catch(error => client.catch(error))
            }).catch(error => client.catch(error)).then(
            server.createChannel(name, "text")).then(
                (channel) => {
                    channel.setParent("542070913177485323")
          })
        } else if (reply.content === 'deny') {
          reply.channel.send("You have ***denied *** the challenge.") 
        } else {
          reply.channel.send("Your response wasn't valid.");
        }
      })
   })
}
module.exports.help = {
    name: "challenge"
}

我已尝试查找问题,但到目前为止我没有看到任何对这两个问题有帮助的东西。它们可能是相关的,因为捕获是在添加角色部分之后?在此先感谢您的帮助!

【问题讨论】:

  • 查看文档中给出的createRole example。至于client.catch错误,是因为Discord客户端没有by the docs所说的catch函数(除非你自己为客户端声明了catch函数)。

标签: javascript node.js client roles discord.js


【解决方案1】:

想知道您是否为此机器人复制了模板? Discord.Client 对象没有任何catch 方法,所以调用client.catch() 是行不通的。

澄清一下,这很好:

challenger.addRole(role, permsName)
.catch(error => /* do something with this error */);

您可以如何处理该错误?我想您可以将其打印到控制台:

challenger.addRole(role, permsName)
.catch(error => console.error(error));

但您不能调用 client.catch(error),因为这不是真正的方法 - 您可以查看文档以了解 Client 对象 here。

关于角色名称,您只是有一个小错误:您不想将选项对象包装在{ data: } 中,您的选项对象是数据。直接传入就行了,像这样:

message.guild.createRole({
    name: permsName,
    hoist: true,
    color: "#00fffa",
    permissions: []
}).then(role => {

希望有帮助!

【讨论】:

  • 是的!那真是奇迹!是的,当我一直试图让它工作时,我一直在使用一些模板。那绝对是我的问题。我也不确定为什么我没有注意到我实际上并不需要“数据”!非常感谢!
猜你喜欢
  • 2021-11-02
  • 2016-09-09
  • 1970-01-01
  • 2012-10-08
  • 2021-06-15
  • 1970-01-01
  • 1970-01-01
  • 2021-07-27
  • 1970-01-01
相关资源
最近更新 更多