Hello, I am currently coding my discord bot so that it can announce on my discord when I launch a stream. The code is done but I do not know how to call the api if someone can help me it would be wonderful
this is my code, what should I change
const snekfetch = require('snekfetch');
const streamer = 'maxtar07';
const api = `https://api.twitch.tv/helix/streams?login=${streamer}`;
const announcements = client.channels.cache.get('757625738252779628');
snekfetch.get(api).then(r => {
if (r.body.stream === null) {
setInterval(() => {
snekfetch.get(api).then(console.log(r.body))
}, 30000);
} else {
const twitch_embed = new Discord.RichEmbed()
.setAuthor(
`${r.body.stream.channel.display_name} is live on Twitch`,
`${r.body.stream.channel.logo}`,
`${r.body.stream.channel.url}`
)
.setThumbnail(`http://static-cdn.jtvnw.net/ttv-boxart/${encodeURI(r.body.stream.channel.game)}-500x500.jpg`)
.addField('Stream Title', `${r.body.stream.channel.status}`, true)
.addField('Playing', `${r.body.stream.channel.game}`, true)
.addField('Followers', `${r.body.stream.channel.followers}`, true)
.addField('Views', `${r.body.stream.channel.views}`, true)
.setImage(r.body.stream.preview.large)
return client.channels.cache.get(announcements.id).send({ twitch_embed });
}
});
Sincerely,
Maxtar07
You need to specify an oAuth token when calling Helix
For this use case a server to server token is most appropriate
thanks but how should I call it in my code?
Refer to the documentation for snekfetch on how to use/specify headers
ok thanks, where can I find the OAuth token and which category should I choose for my twitch application to have a client ID?
Which ever is most appropriate for your use case
You can generate one using the ClientID and client secret as documented
I don’t know which one to choose because this app is not going to be useful to me except for retrieving the client id
Then just pick broadcaster tools or something.
Whatever the cloest option is. It’s up to you to determine that.
Selecting the option dones’t change how the clientID functions, it’s just informative in case Twitch needs to contact you about your usage

I don’t understand that…I have to do a command : POST https://etc…etc…etc… ?but where ?
As per your code.
You tried to use snekfetch to call helix.
But you didn’t specify a token.
So you can use snekfetch to make a POST call to generate a token.
axios.post(`https://id.twitch.tv/oauth2/token?client_id=${clientid}&client_secret=${clientsecret}&grant_type=client_credentials`).then(response => {
accessToken = response.data.access_token;
console.log(accessToken)
})
let api = axios.create({
headers: {
'Client-ID': `${clientid}`,
'Authorization': `Bearer ${accessToken}`
}
})
I think it is good but I have an error :
0|main | TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received function wrap
0|main | at validateString (internal/validators.js:124:11)
0|main | at Url.parse (url.js:159:3)
0|main | at urlParse (url.js:154:13)
0|main | at /root/node_modules/snekfetch/src/node/index.js:25:28
0|main | at new Promise (<anonymous>)
0|main | at Object.request (/root/node_modules/snekfetch/src/node/index.js:24:10)
0|main | at Snekfetch.then (/root/node_modules/snekfetch/src/index.js:147:39)
0|main | at Object.<anonymous> (/root/main.js:62:22)
0|main | at Module._compile (internal/modules/cjs/loader.js:1063:30)
0|main | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
0|main | at Module.load (internal/modules/cjs/loader.js:928:32)
0|main | at Function.Module._load (internal/modules/cjs/loader.js:769:14)
0|main | at Object.<anonymous> (/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js:33:23)
0|main | at Module._compile (internal/modules/cjs/loader.js:1063:30)
0|main | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
0|main | at Module.load (internal/modules/cjs/loader.js:928:32) {
0|main | code: 'ERR_INVALID_ARG_TYPE'
0|main | }
So you’ve switched from sneakfetch to axios?
Bit you got a sneakfetch error?
I don’t use axios or sneakfetch so refer their instructions of advice on correct construction
it’s okay, after a lot of researches, i found all I want
Thanks a lot for your help