mirror of
https://github.com/xHyroM/roles-bot.git
synced 2024-11-24 01:01:06 +01:00
feat: return channels
This commit is contained in:
parent
a865aa5532
commit
3cc2dd758a
2 changed files with 24 additions and 5 deletions
|
@ -14,6 +14,20 @@ export async function getGuild(
|
|||
return guild;
|
||||
}
|
||||
|
||||
export async function getGuildChannels(guildId: string, env) {
|
||||
const discordApiGuildChannelsResponse = await fetch(
|
||||
`https://discord.com/api/v10/guilds/${guildId}/channels`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bot ${env.DISCORD_BOT_TOKEN}`,
|
||||
"Cache-Control": "max-age=300",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return await discordApiGuildChannelsResponse.json();
|
||||
}
|
||||
|
||||
export async function getUserGuilds(user): Promise<Guild[]> {
|
||||
const discordApiGuildsResponse = await fetch(
|
||||
"https://discord.com/api/v10/users/@me/guilds",
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
import type { APIRoute } from "astro";
|
||||
import { filterUserGuilds, getUserGuilds } from "~/lib/guilds";
|
||||
import type { APIContext, APIRoute } from "astro";
|
||||
import { getGuildChannels } from "~/lib/guilds";
|
||||
|
||||
export const GET: APIRoute = async ({ locals }) => {
|
||||
interface APIParams {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export const GET: APIRoute = async ({ params, locals }) => {
|
||||
const user = locals.user;
|
||||
if (!user) {
|
||||
return new Response(null, {
|
||||
|
@ -9,6 +13,7 @@ export const GET: APIRoute = async ({ locals }) => {
|
|||
});
|
||||
}
|
||||
|
||||
console.log(user);
|
||||
return Response.json([]);
|
||||
const channels = await getGuildChannels(params.id!, locals.runtime.env);
|
||||
|
||||
return Response.json(channels);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue