P
P
PanCar2021-06-16 01:02:40
PHP
PanCar, 2021-06-16 01:02:40

How to get a Discord user's avatar through the Discord API in PHP and display it on the site?

Good day! Sorry if this is a stupid question, I'm just a newbie. I'm doing authentication through Discord in php. And I decided to display the user's avatar (after he logs in), but when I tried to display the avatar, it didn't work for me. And these numbers were displayed
60c9222d6b4f6042364072.png
The code that I took for the output:
$avatar = apiRequest($apiURLBase);
echo $avatar->avatar;
And yes I read this: https://discord.com/developers/docs/game-sdk/users... but there is no code for php

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PanCar, 2021-06-17
@PanCar

I figured out how to do it. At the end, we should have something like this:

echo "<img src='https://cdn.discordapp.com/avatars/$user->id/$user->avatar'>";

Let me explain how it works. First we write it
$user = apiRequest(https://discordapp.com/api/users/@me);
We take this from the API name, id , discriminator, avatar and so on, the whole list: https://discord.com/developers/docs/resources/user . After that we take where all the avatars of discord users are located https://cdn .discordapp.com/avatars/ .After that we take the id of the user whose avatar we want to take $user->id and after that we write /$user->avatar this we get the user's avatar and after that we get the link. And we insert this so that it is a picture, we get this
<img src='https://cdn.discordapp.com/avatars/$user->id/$user->avatar'>
and just add echo and you're done, we get the output of the picture

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question