I am trying to display in my HTML website all the members who have a specific role (for example to display all members that have the "boss" role in my server) but i cant find anything to do it. I have some code that finds the member counter which i am not sure if its any similar to what i need to do. the code is as follows (also i need to mention that i am a beginner in JS)
<span id="discord-counter"></span>
<script type="text/javascript">
var request = new XMLHttpRequest();
request.open('GET', 'https://discordapp.com/api/guilds/792895591255769098/embed.json', true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
// Success!
console.log("Success")
var data = JSON.parse(request.responseText);
document.getElementById("discord-counter").innerHTML = data.members.length;
} else {
console.log("We reached our target server, but it returned an error")
// We reached our target server, but it returned an error
}
};
request.onerror = function() {
// There was a connection error of some sort
};
request.send();
</script>
With "modern" browsers it has become much easier to get server data asynchronously by using fetch()
. In the following snippet I filtered for members that have a status of "online":
fetch("https://discordapp.com/api/guilds/792895591255769098/embed.json").then(r=>r.json()).then(d=>console.log(d.members.filter(e=>e.status=="online")));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.