Next.js Discord

Discord Forum

Is it possible to use Discord.js wrapper in Next js?

Unanswered
Griffon Bleu de Gascogne posted this in #help-forum
Open in Discord
Griffon Bleu de GascogneOP
Hi, im trying to figure out how to use Discord.js in my nextjs project, or even if its possible. I'm currently using the REST api, but would need discord.js for my other features. Any response will be greatly appreciated.

Code:

import { REST } from '@discordjs/rest';
import { Routes } from 'discord-api-types/v10';
import { token } from '@/discord.json';
import { NextResponse } from 'next/server';

const rest = new REST({ version: "10" }).setToken(token);

export async function POST(request: Request, { params }: { params: { guildId: string } }) {

    try {

        const { guildId } = await params;

        const body = await request.json();
        const { lobbyName } = body;

        const category = await rest.post(
            Routes.guildChannels(guildId),
            {
                body: {
                    name: lobbyName,
                    type: 4
                },
            }
        );

        const channel = await rest.post(
            Routes.guildChannels(guildId),
            {
                body: {
                    name: "lobby-1-registration",
                    type: 0,
                    // @ts-ignore
                    parent_id: category.id,
                },
            }
        );

        return NextResponse.json({ success: true, data: body }, { status: 200 });

    } catch (error) {
        console.error('Error:', error);
        return NextResponse.json({ success: false, error: 'Failed to fetch data' }, { status: 500 });
    }
}

2 Replies

Griffon Bleu de GascogneOP
bump
Asian black bear
Please note that bumping is only allowed after 24h.