My code is returning some error
UnhandledPromiseRejectionWarning: Error: 404 Not Found at _response.transport.request.then (/app/node_modules/snekfetch/src/index.js:193:21) at process._tickCallback (internal/process/next_tick.js:68:7) (node:23) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 8)
Here's my node.js code:
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;
(sorry it's too long, I can't put it here)
https://api.roblox.com/users/get-by-username?username=using postman or your terminal? - Liang-Shih Lincurl https://api.roblox.com/users/get-by-username?username=- Liang-Shih Lin