Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript中未处理的PromisejectionWarning错误_Javascript_Node.js - Fatal编程技术网

Javascript中未处理的PromisejectionWarning错误

Javascript中未处理的PromisejectionWarning错误,javascript,node.js,Javascript,Node.js,我的代码返回了一些错误 未处理的PromisejectionWarning:错误:找不到404 在_response.transport.request.then(/app/node\u modules/snekfetch/src/index.js:193:21) 在进程中。_tick回调(内部/process/next_tick.js:68:7) (节点:23)未处理的PromisejectionWarning:未处理的承诺拒绝。此错误源于在没有catch块的异步函数中抛出,或者拒绝未使用.c

我的代码返回了一些错误

未处理的PromisejectionWarning:错误:找不到404 在_response.transport.request.then(/app/node\u modules/snekfetch/src/index.js:193:21) 在进程中。_tick回调(内部/process/next_tick.js:68:7) (节点:23)未处理的PromisejectionWarning:未处理的承诺拒绝。此错误源于在没有catch块的异步函数中抛出,或者拒绝未使用.catch()处理的承诺。(拒绝id:8)

下面是我的node.js代码:

  console.log('Turned on Discord bot');
  bot.user.setActivity(`${bot.users.size} comrades!`, { type: 'WATCHING' });
  bot.channels.get(bot.channels.get(`${mainChatChannelID}`).id).send(`**Resuming processes!** :wave:`)
})

bot.on('message', async message => {

  const args = message.content.split(/[ ]+/)
  const promoLogs = bot.channels.get(`${xpAuditLogChannelID}`)
  const officerRole = message.guild.roles.find(role => role.name === `${officerRoleE}`);
  const groupFunction = await bloxyClient.getGroup(groupID)

  if (message.content.toLowerCase().startsWith(`${prefix}${xpName}`)){
    if (!message.member.roles.exists("name", `${officerRoleE}`)){
      return message.channel.send(`Sorry ${message.author}, but only users with the **\`${officerRoleE}\`** can run that command!`).then(message => message.delete(5000));
    }
    if (!args[1]){
      return message.channel.send(`Sorry ${message.author}, but you're missing the first argument--add or remove?\n**Adding ${xpName}: \`${prefix}${xpName} add 1 username1, username2, username3...\`\nRemoving ${xpName}: \`${prefix}${xpName} remove 1 username1, username2, username3...\`**`).then(message => message.delete(5000));
    }else if (args[1].toLowerCase() !== "add" && args[1].toLowerCase() !== "remove"){
      return message.channel.send(`Sorry ${message.author}, but you didn't provide me with a correct first argument--add or remove?\n**Adding ${xpName}: \`${prefix}${xpName} add 1 username1, username2, username3...\`\nRemoving ${xpName}: \`${prefix}${xpName} remove 1 username1, username2, username3...\`**`).then(message => message.delete(5000));
    }else{
      if (!args[2]){
        return message.channel.send(`Sorry ${message.author}, but you're missing the second argument--number of ${xpName}?\n**Adding ${xpName}: \`${prefix}${xpName} add 1 username1, username2, username3...\`\nRemoving ${xpName}: \`${prefix}${xpName} remove 1 username1, username2, username3...\`**`).then(message => message.delete(5000));
      }else if (isNaN(Number(args[2]))){
        return message.channel.send(`Sorry ${message.author}, but you didn't provide me with a real number.\n**Adding ${xpName}: \`${prefix}${xpName} add 1 username1, username2, username3...\`\nRemoving ${xpName}: \`${prefix}${xpName} remove 1 username1, username2, username3...\`**`).then(message => message.delete(5000));
      }else if (args[2] < 0){
        return message.channel.send(`Sorry ${message.author}, but you need to provide me with a positive number.\n**Adding ${xpName}: \`${prefix}${xpName} add 1 username1, username2, username3...\`\nRemoving ${xpName}: \`${prefix}${xpName} remove 1 username1, username2, username3...\`**`).then(message => message.delete(5000));
      }else if (args[2] > maxXP){
        return message.channel.send(`Sorry ${message.author}, but you need to provide mw with a number that's less than the max ${xpName}--currently set at ${maxXP} ${xpName}.\n**Adding ${xpName}: \`${prefix}${xpName} add 1 username1, username2, username3...\`\nRemoving ${xpName}: \`${prefix}${xpName} remove 1 username1, username2, username3...\`**`).then(message => message.delete(5000));
      }else if (!args[3]){
        return message.channel.send(`Sorry ${message.author}, but you're missing the third argument--the usernames!\n**Adding ${xpName}: \`${prefix}${xpName} add 1 username1, username2, username3...\`\nRemoving ${xpName}: \`${prefix}${xpName} remove 1 username1, username2, username3...\`**`).then(message => message.delete(5000));
      }else{
        if (args[1].toLowerCase() === "add"){
          var userArray = message.content.slice(message.content.indexOf(message.content.split(" ")[3])).split(', ');
          for (i = 0; i < userArray.length; i++){
            var { body } = await snekfetch.get(`https://api.roblox.com/users/get-by-username?username=${userArray[i]}`);
            if (body.success === false){
              var errorEmbed = new Discord.RichEmbed()
                .setColor(0xff4040)
                .setDescription(`:warning: **${userArray[i]} doesn't exist on ROBLOX** :warning:`);
                await message.channel.send(errorEmbed);
            }else{
              var userID = await rbx.getIdFromUsername(`${userArray[i]}`);
              var { body } = await snekfetch.get(`${fireBaseURL}/xpData/users/${userID}.json`);
              var currentXP;
console.log('打开Discord bot');
bot.user.setActivity(`${bot.users.size},`,{type:'WATCHING'});
bot.channels.get(bot.channels.get(`mainChatChannelID}').id).send(`**正在恢复进程!**:wave:`)
})
bot.on('message',异步消息=>{
常量args=message.content.split(/[]+/)
const promoLogs=bot.channels.get(`${xpAuditLogChannelID}`)
const officerole=message.guild.roles.find(role=>role.name==`${officerolee}`);
const groupFunction=await bloxyClient.getGroup(groupID)
if(message.content.toLowerCase().startsWith(`${prefix}${xpName}`){
如果(!message.member.roles.exists(“name”、`${officerRoleE}`))存在{
return message.channel.send(`Sorry${message.author},但只有使用**\`${officerRoleE}\`**的用户才能运行该命令!`);
}
如果(!args[1]){
返回message.channel.send(`Sorry${message.author},但您缺少第一个参数--add或remove?\n**添加${xpName}:\`${prefix}${xpName}添加1个用户名1、用户名2、用户名3…\`\n删除${xpName}:\`${prefix}${xpName}删除1个用户名1、用户名2、用户名3…\```)。然后(message message=>message.delete(5000));
}else if(args[1].toLowerCase()!==“添加”&&args[1].toLowerCase()!==“删除”){
返回message.channel.send(`Sorry${message.author},但您没有为我提供正确的第一个参数--add或remove?\n**Adding${xpName}:\`{prefix}${xpName}${xpName}添加1个用户名1、用户名2、用户名3…\`\n删除${xpName}:\`${xpName}删除1个用户名1、用户名2、用户名3…`**)。然后(message message message message message message delete(5000));
}否则{
如果(!args[2]){
返回message.channel.send(`Sorry${message.author},但是您缺少第二个参数--${xpName}的数量?\n**添加${xpName}:\`{prefix}${xpName}添加1个用户名1、用户名2、用户名3…\`\n删除${xpName}:\`${prefix}${xpName}删除1个用户名1、用户名2、用户名3…\`**)。然后(message message=>message delete(5000));
}else if(isNaN(编号(args[2])){
返回message.channel.send(`Sorry${message.author},但您没有给我提供真实的数字。\n**添加${xpName}:\`${prefix}${xpName}添加1个用户名1、用户名2、用户名3…\`\n删除${xpName}:\`${prefix}${xpName}删除1个用户名1、用户名2、用户名3…\````。然后(message=>message message.delete(5000));
}else if(args[2]<0){
返回message.channel.send(`Sorry${message.author},但您需要为我提供一个正数。\n**添加${xpName}:\`${prefix}${xpName}添加1个用户名1,用户名2,用户名3…\`\n删除${xpName}:\`${prefix}${xpName}删除1个用户名1,用户名2,用户名3…\````)。然后(message=>message message.delete(5000));
}else if(args[2]>maxXP){
返回message.channel.send(`Sorry${message.author},但您需要为mw提供一个小于当前设置为${maxXP}${xpName}的max${xpName}的数字。\n**添加${xpName}:\`${prefix}${xpName}添加1个用户名1、用户名2、用户名3…`\n删除${xpName}:\`{prefix}${xpName}${xpName}删除1个用户名1、用户名2、用户名3…`)(message=>message.delete(5000));
}如果(!args[3]){
return message.channel.send(`Sorry${message.author},但是您缺少第三个参数--用户名!\n**Adding${xpName}:\`${prefix}${xpName}添加1个用户名1,用户名2,用户名3…\`\n删除${xpName}:\`${prefix}${xpName}删除1个用户名1,用户名2,用户名3…\```)。然后(message message=>message.delete(5000));
}否则{
if(args[1].toLowerCase()=“添加”){
var userArray=message.content.slice(message.content.indexOf(message.content.split(“”[3]).split(“,”);
对于(i=0;i
(对不起,太长了,我不能放在这里)

在没有catch块的情况下抛出异步函数的内部,或者 拒绝未使用.catch()处理的承诺

我认为这说明了一切,使用async await很好,但您必须尝试捕获块, 也许你可以试试这个:

try{    
  const groupFunction = await bloxyClient.getGroup(groupID)
  //with the following of your code or encapsulate the rest in a function.
}catch (err){
  return console.log(err)
}
也许它能按原样工作:

let groupFunction;
try{    
  groupFunction = await bloxyClient.getGroup(groupID)
  //with the following of you code or encapsulate the rest in a function.
}catch (err){
  return console.log(err)
}

您所有的“等待”都必须尝试/捕获

当您手动调用
https://api.roblox.com/users/get-by-username?username=
使用邮递员或您的终端?我使用Heroku作为主机。您所说的“手动”是什么意思调用它?
curlhttps://api.roblox.com/users/get-by-username?username=
如果您不在基于Unix的系统上,请使用Postman。即使我修复了它,它仍然会显示错误。我用我的代码替换您的答案,因为整个代码中只有一个异步函数。它还说明了一个承诺。我是Javascript新手,那么,你能解释一下我在代码中从哪里找到所谓的“承诺”,这样我就可以修复它了吗?谢谢