I'm currently trying to request discord API to get a list of all available channels inside a server, but when I'm running my request I get the error:
Failed to fetch
I really don't know why. I already tried on Postman and with Restsharp in C# and it work perfectly.
The fact is that I succeed to get a list of all guilds with this code :
var detectGuilds= async () => {
const response = await fetch('https://discord.com/api/users/@me/guilds', {
method: 'GET',
headers: {
'Authorization': 'Bot myBotToken'
}
});
const result = await response.json();
}
But I don't know why with the exact same code for channels it failed :
var detectChannels= async () => {
var idSelectedGuild = dictGuilds[document.getElementById("comboGuilds").value];
var uri =`https://discord.com/api/guilds/${idSelectedGuild}/channels`;
var uri2 ="https://discord.com/api/v10/guilds/94055174550578/channels"
const response = await fetch(uri, {
method: 'GET',
headers: {
'Authorization': 'Bot myBotToken',
//'User-Agent' : 'Mozilla/5.0 (compatible; Discordbot/2.0; +https://discordapp.com)'
}
});
const result = await response.json();
alert(result)
}
---------------------------------------------------------------------
Uncaught TypeError TypeError: Failed to fetch
at detectChannels (c:\Users\Moi\Downloads\test.html:173:28)
at onchange (c:\Users\Moi\Downloads\test.html:104:77)
--- await ---
at onchange (c:\Users\Moi\Downloads\test.html:104:77)
at handleMouseUp_ (undefined:586:32)
I spent a lot of time on it and I can't figure out what the problem is
Has anyone got an answer?