TActivePlayer.RequestDiscordToken

From Soldat Community Wiki
Jump to: navigation, search
procedure RequestDiscordToken

Description

Sends a request to retrieve player's discord OAuth2 token, on a successful call server will receive a /discord_token command with the token.

This request works only on players who are using the desktop version of Discord.

Example

procedure OnJoin(Player: TActivePlayer; Team: TTeam);
begin
   Player.RequestDiscordToken;
end;

function OnCommand(Player: TActivePlayer; Command: string): Boolean;
var
  Token: String;
begin
  if Copy(Command, 1, 15) = '/discord_token ' then
  begin
    Token := Copy(Command, 16, Length(Command));
    // Use 3rdparty library to call and parse response from discord api
    // Curl bash example: curl -H 'Authorization: Bearer TOKEN' https://discordapp.com/api/users/@me
  end;
end;

var 
  i: Byte;
begin
  Game.OnJoin := @OnJoin;
  for i:=1 to 32 do
    Players[i].OnCommand := @OnCommand;
end;