Hello there,
I am having an issue with the discord bot I am making.
What I am using:
nodejs
axios
express
twitch api
I am building a custom discord bot for a friend that will tell when a streamer goes live. I was testing my creation, and was able to get my notification anytime my personal stream went live, we tested with his twitch, and nothing. We then had a friend each go live, and both went through.
after the second or third time we were able to get the error output for when he went live:
TypeError: Cannot read property 'user_id' of undefined
at app.post (/var/www/html/discordCB/DiscordChatBotTemplate/app.js:59:29)
which pertains to these lines of code with the last being the error:
app.post('/userLive', jsonParser, (req, res) => {
//body is the parameters that are being sent.
let body = req.body;
console.log(body);
let data = body.data[0];
twitch.getUserData(data.user_id, data.game_id, function(user, game){
we have tested 4 twitch accounts in total, the only difference that I see is that his USERNAME has an underscore. But, even then, we do not use the username we use the USER_ID.
I have used a chrome extension and put his user id in to it and gotten back his username, and vise versa. I have used this script:
async function getUserId(username){
let userid = await axios.get('https://api.twitch.tv/helix/users?login='+username);
return userid.data.data[0].id;
}
to get back both ID and username.
Any Idea of what it could be?