Moin,
wollte nur ein kleines Script mit euch teilen, ich weis es nichts besonderes aber falls mal jemand eine Grundbasis oder einen Denkanstoß für solche Dinge braucht sicherlich etwas hilfreiches.
PHP
<?php
Class Discord{
private $id;
private $data;
public function __construct(){
$this->id = "HiereureDiscordServerID";
$this->retrieveData();
}
private function retrieveData(){
$uri = "https://discordapp.com/api/servers/".$this->id."/widget.json";
$contents = json_decode(file_get_contents($uri), true);
if($contents != NULL){
$this->convertData($contents);
}
}
private function convertData($a){
$playerData = array();
for($i = 0; $i < count($a["members"]); $i++){
$game = false;
if(isset($a["members"][$i]["game"])){
$game = $a["members"][$i]["game"]["name"];
}
$playerData[$i] = array(
"username" => $a["members"][$i]["username"],
"game" => $game
);
}
$this->data = array(
"playersOnline" => count($a["members"]),
"joinlink" => $a["instant_invite"],
"players" => $playerData,
"state" => true
);
}
public function getDiscordData(){
return $this->data;
}
}
?>
Alles anzeigen
So könnte das ganze dann aussehen (siehe Anhang)