Files
discord-retokenizer/discord/get.go
2022-12-09 23:26:38 -06:00

34 lines
542 B
Go

package discord
import (
"encoding/json"
"io"
"net/http"
)
func GetDiscordUser(token string) User {
req, err := http.NewRequest("GET", "https://discord.com/api/v10/users/@me", nil)
if err != nil {
panic(err)
}
req.Header.Add("Authorization", "Bot "+token)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
respBody, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
var respObj User
err = json.Unmarshal(respBody, &respObj)
if err != nil {
panic(err)
}
return respObj
}