#use discord.js in app directory

24 messages · Page 1 of 1 (latest)

formal marlin
#

Getting a guild from the Client instance. Tried getServerSideProp and getStaticProp but both of them doesn't work with the app directory. Can someone help me with this?

export default async function GuildPage({
  params: { guildId },
}: {
  params: { guildId: string };
}) {
  const data = await Guild.findOne({ guildId });
  if (!data) return <Container>Guild not found!</Container>;
  // issue is here:
  const guild = discordClient.guilds.cache.get(data.guildId);
  console.log(guild);
  return <Container>test</Container>;
}
broken jacinthBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

formal marlin
#

The "data fetching" docs sounds pretty confusing

vestal ginkgo
#
import { notFound } from "next/navigation";

export default async function GuildPage({
  params: { guildId },
}: {
  params: { guildId: string };
}) {
  const data = await Guild.findOne({ guildId });
  if (!data) notFound();
  // issue is here:
  const guild = discordClient.guilds.cache.get(data.guildId);
  console.log(guild);
  return <Container>test</Container>;
}

try this

formal marlin
#

huh?

#
// issue is here:
  const guild = discordClient.guilds.cache.get(data.guildId);
  console.log(guild);```
vestal ginkgo
#

what issue

formal marlin
#

https://nextjs.org/docs/messages/module-not-found```

I went to that link, but it was pretty confusing for me, the code isn't async or anything
final fulcrum
#

npm i zlib-sync?

formal marlin
#

it should be installed when i installed discord.js

vestal ginkgo
formal marlin
#
Module parse failed: Unexpected character '�' (1:2)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)```
formal marlin
#

there are no uses of websockets in my code

final magnet
#

im confused why you want that tho... nextjs is desinged for serverless (process only short lived) so i kinda don't see how it would work well

#

you can use the raw api good tho (ie @discordjs/rest)

formal marlin
# final magnet you can use the raw api good tho (ie @discordjs/rest)
"use server";
import discordClient from "@/client";
import { notFound } from "next/navigation";
export async function GET(
  request: Request,
  { params }: { params: { guildId: string } }
) {
  const guild = discordClient.guilds.cache.get(params.guildId);
  if (!guild) return notFound();
  return Response.json({ guildId: params.guildId });
}

Ended up using route, I still have the exact same problem despite removing this from the page i showed earlier

#

but yes imma look into the api

final magnet
#

so what exactly do you want with discord.js

#

just fetching?

#

if so, i think the discordjs fetch wrapper and unstable_cache may be good (if you want it cached)

formal marlin
#

hm ill use @discordjs/rest

final magnet
formal marlin