Hi! I am using the twitch api along with discord.js to make a command that gets results from the twitch api and sends them in a message (this is probably a bad idea but its not a big bot anyways :P). This works great (I use a ```json codeblock), except when I am using, say, https://api.twitch.tv/helix/search/categories?query=something
, and the result is over 2000 characters and I get a big nasty error in terminal. I was wondering if you could somehow (preferably without using fs
but if thats not possible it’s already imported) that I could export the raw JSON file and send that in a message (message.channel.send({files: res.json or whatever its called})
)
My current code is this:
fetch('https://id.twitch.tv/oauth2/token?client_id=' + process.env.clientId + "&client_secret=" + process.env.clientSecret + "&grant_type=client_credentials", {
method: 'POST',
})
.then(res => {
res.json()
message.reply({files: res.json})
})
.then(res => {
var token = res.access_token
try {
fetch(url + game, {
method: 'GET',
headers: {
'Client-ID': process.env.clientId,
'Authorization': 'Bearer ' + token,
}
})
.then(res => res.json())
.then(res => {
var result = JSON.stringify(res, null, 4)
if(result.length > 2000){
//export the file
} else {
message.channel.send("```json\n" + result + "\n```")
})
Any help is appreciated