Skip to content

Commit beb7916

Browse files
committed
fix: convert discord.js import to dynamic in client-direct
Static import of discord.js in api.ts crashes the agent on startup when @discordjs/builders has compatibility issues. Moved to dynamic import inside the /channels endpoint handler since it's only needed for Discord guild queries. Made-with: Cursor
1 parent c84e892 commit beb7916

File tree

1 file changed

+4
-2
lines changed
  • packages/client-direct/src

1 file changed

+4
-2
lines changed

packages/client-direct/src/api.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import {
1515
} from "@elizaos/core";
1616

1717
import type { TeeLogQuery, TeeLogService } from "@elizaos/plugin-tee-log";
18-
import { REST, Routes } from "discord.js";
18+
// discord.js import moved to dynamic to avoid crash when discord dependencies have issues
19+
// import { REST, Routes } from "discord.js";
1920
import type { DirectClient } from ".";
2021
import { validateUuid } from "@elizaos/core";
2122

@@ -226,9 +227,10 @@ export function createApiRouter(
226227
}
227228

228229
const API_TOKEN = runtime.getSetting("DISCORD_API_TOKEN") as string;
229-
const rest = new REST({ version: "10" }).setToken(API_TOKEN);
230230

231231
try {
232+
const { REST, Routes } = await import("discord.js");
233+
const rest = new REST({ version: "10" }).setToken(API_TOKEN);
232234
const guilds = (await rest.get(Routes.userGuilds())) as Array<any>;
233235

234236
res.json({

0 commit comments

Comments
 (0)