So I'm new to Javascript and trying to making a discord bot. Here is a very small portion that illustrates my problem:
module.exports = {
name: "match",
category: "LOL",
description: "Give Summoner's Data to User",
run: async (client, message, args) => {
var username = `${args}`
var regionID= "na1"
pyke.summoner.getBySummonerName(username, regionID).then(data => {
return pyke.spectator.getCurrentGameInfoBySummoner(`${data.id}`, "na1").then(result => {
try {
console.log(result)
} catch (err) {
console.error(`${args} isn't in game!`)
}
})
})
}
}
I was expected to see if an error cause, it will send a code to a console. However, I get a UnhandledPromiseRejectionWarning
. My question is why can't I catch an error and send a code to the console?
So This is what I try for the command
const property1 = result.participants.summonerName
const BResult = property1
let FResult = JSON.stringify(BResult)
message.channel.send(FResult)
and when I try, I got an error says that this person isn't in-game. I know it's false because they are in-game.
So I went further and try to do this instead.
const property1 = result.participants[summonerName]
const BResult = property1
let FResult = JSON.stringify(BResult)
message.channel.send(FResult)
I still get the same result from the last one. I also try to do const property1 = result.summonerName
, but it didn't work as well.