mirror of
https://github.com/supleed2/ICAS.git
synced 2024-12-22 22:05:49 +00:00
Add endpoint to get Discord Username/Avatar
This commit is contained in:
parent
c09a55465d
commit
e56fbc5e41
21
html/functions/discord.ts
Normal file
21
html/functions/discord.ts
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
export async function onRequestGet({ request, env }) {
|
||||||
|
const id = new URL(request.url).searchParams.get("id");
|
||||||
|
const { username, avatar } = await fetch(`https://discord.com/api/v9/users/${id}`, {
|
||||||
|
headers: { Authorization: `Bot ${env.DISCORD_TOKEN}`, },
|
||||||
|
}).then((r) => r.json()).catch(console.error);
|
||||||
|
if (username == undefined) {
|
||||||
|
return new Response(JSON.stringify({
|
||||||
|
username: "User not found.",
|
||||||
|
avatar_url: "https://cdn.discordapp.com/embed/avatars/0.png",
|
||||||
|
}), {
|
||||||
|
headers: { "content-type": "application/json;charset=UTF-8", },
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return new Response(JSON.stringify({
|
||||||
|
username: username,
|
||||||
|
avatar_url: `https://cdn.discordapp.com/avatars/${id}/${avatar}.png`,
|
||||||
|
}), {
|
||||||
|
headers: { "content-type": "application/json;charset=UTF-8", },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue