Mr. Fox
DIdiscord.js - Imagine ❄
•Created by Mr. Fox on 5/12/2024 in #djs-questions
@discordjs/rest & Nextjs v14 error
I'm trying to create a dashboard with Next.js to manage a Discord server and organize some stuff like events and tournaments on it, but when using the discord.js REST, I encounter this error.
Error:
Code:
Node Version:
⨯ ./node_modules/undici/lib/web/fetch/util.js
Module parse failed: Unexpected token (874:57)
| // 5. If object is not a default iterator object for interface,
| // then throw a TypeError.
> if (typeof this !== 'object' || this === null || !(#target in this)) {
| throw new TypeError(
| `'next' called on an object that does not implement interface ${name} Iterator.`
Import trace for requested module:
./node_modules/undici/lib/web/fetch/util.js
./node_modules/undici/lib/web/fetch/index.js
./node_modules/undici/index.js
./node_modules/@discordjs/rest/dist/index.mjs
./src/app/api/channel/announcement/route.ts
⨯ ./node_modules/undici/lib/web/fetch/util.js
Module parse failed: Unexpected token (874:57)
| // 5. If object is not a default iterator object for interface,
| // then throw a TypeError.
> if (typeof this !== 'object' || this === null || !(#target in this)) {
| throw new TypeError(
| `'next' called on an object that does not implement interface ${name} Iterator.`
Import trace for requested module:
./node_modules/undici/lib/web/fetch/util.js
./node_modules/undici/lib/web/fetch/index.js
./node_modules/undici/index.js
./node_modules/@discordjs/rest/dist/index.mjs
./src/app/api/channel/announcement/route.ts
import { type NextRequest, type NextResponse } from "next/server";
import { Routes } from 'discord-api-types/rest/v10'
import { REST } from '@discordjs/rest'
export async function GET(request: NextRequest, response: NextResponse) {
const channelId = "id-of-the-channel"
const rest = new REST({ version: "10", authPrefix: "Bearer", makeRequest: fetch }).setToken("user-token")
try {
const data = await rest.get(Routes.channelMessages(channelId))
// ... rest of the code
} catch (e) {
console.error(e)
return Response.json([])
}
}
import { type NextRequest, type NextResponse } from "next/server";
import { Routes } from 'discord-api-types/rest/v10'
import { REST } from '@discordjs/rest'
export async function GET(request: NextRequest, response: NextResponse) {
const channelId = "id-of-the-channel"
const rest = new REST({ version: "10", authPrefix: "Bearer", makeRequest: fetch }).setToken("user-token")
try {
const data = await rest.get(Routes.channelMessages(channelId))
// ... rest of the code
} catch (e) {
console.error(e)
return Response.json([])
}
}
18.18.0
2 replies