hello world
This commit is contained in:
34
discord/get.go
Normal file
34
discord/get.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package discord
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func getDiscordUser(token string) User {
|
||||
req, err := http.NewRequest("GET", "https://discord.com/api/v19/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
|
||||
}
|
||||
Reference in New Issue
Block a user