'how do i get the discord role data from a guild using an API call

i have this code in JS however it always returns a 403 error when i run it in my website. I have tried to run the same request with python and in postman and it gave me the data i wanted so the API is definitly not the problem. it also gave me a CORS error which i resolved by getting a chrome extension but i am not sure if that is the problem

const url="https://discord.com/api/v9/guilds/792895591255769098/members/search"

function callAPI() {
  var xhttp = new XMLHttpRequest();
  xhttp.open('GET', url);
  xhttp.setRequestHeader('Authorization', 'Bot <my bots token>');
  xhttp.send();
  console.log("sent request")
  console.log(xhttp)
}
callAPI.call() 

I also tried this code too but it returns the same result

async function getGuildRoles(){
  const response = await fetch('https://discord.com/api/guilds/792895591255769098/members',{
    method:'GET',
    headers: {
      Authorization: 'Bot <my bots token>'

    }
  });
  console.log(response.text());
  return response;
}
getGuildRoles.call()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source