client.catch 不是一个函数,角色一直在使用 "new role" 而不是我指定的名称?

client.catch is not a function and role keeps making "new role" instead of name I specify?

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

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

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

我遇到的另一个问题是,在目标接受后,我试图让机器人所扮演的角色成为两个 players/users(挑战者与目标格式)的名称挑战者提出的挑战。它只是创建一个名为 "new role" 的角色。对这两个问题有帮助吗?

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"
}

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

想知道您是否为这个机器人复制了一个模板? 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 => {

希望对您有所帮助!