veksen
veksen
DIAdiscord.js - Imagine an app
Created by Mark on 5/25/2025 in #djs-questions
i got error for removing the semi colon
do read what I said tho: HIGHLY recommend yourself to equip yourself with Prettier and auto insert them (or remove), regardless of the setting you use, Prettier will cover your ass from ASI
43 replies
DIAdiscord.js - Imagine an app
Created by Mark on 5/25/2025 in #djs-questions
i got error for removing the semi colon
const rest = new REST().setToken(yourToken)
[...commands].forEach()
const rest = new REST().setToken(yourToken)
[...commands].forEach()
then
43 replies
DIAdiscord.js - Imagine an app
Created by veksen on 5/25/2025 in #djs-questions
Testing djs commands/flows
right ok, thank you
8 replies
DIAdiscord.js - Imagine an app
Created by Mark on 5/25/2025 in #djs-questions
i got error for removing the semi colon
if you're new to JS, very much consider using semicolons, and even better use a tool like Prettier that manages them for you. Prettier would handle this edge case knowing you can't do fn() () the JS reasoning is that this would attempt to call a function that's the return of your previous function, for example:
function fn() {
return function () {
console.log("do something..")
}
}

fn()() // logs "do something.."
function fn() {
return function () {
console.log("do something..")
}
}

fn()() // logs "do something.."
43 replies
DIAdiscord.js - Imagine an app
Created by veksen on 5/25/2025 in #djs-questions
Testing djs commands/flows
Yeah I’ve taken such approach. Abstracted the reply method, and spy on that
8 replies
DIAdiscord.js - Imagine an app
Created by veksen on 5/25/2025 in #djs-questions
Testing djs commands/flows
To expand, my current mocking is someting like this:
vi.mock("discord.js", async () => {
const actual = await vi.importActual("discord.js");
return {
...actual,
EmbedBuilder: vi.fn().mockImplementation(() => ({
setTitle: vi.fn().mockReturnThis(),
setDescription: vi.fn().mockReturnThis(),
setColor: vi.fn().mockReturnThis()
}))
};
});

// mocked interaction
type MockChatInputCommandInteraction = Pick<
ChatInputCommandInteraction,
"deferReply" | "editReply" | "user"
>;

let mockInteraction: MockChatInputCommandInteraction;

beforeEach(async () => {
vi.clearAllMocks();

await resetTestDatabase();

mockInteraction = {
deferReply: vi.fn().mockResolvedValue(undefined),
editReply: vi.fn().mockResolvedValue(undefined),
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
user: {
id: "123456789"
}
};
});
vi.mock("discord.js", async () => {
const actual = await vi.importActual("discord.js");
return {
...actual,
EmbedBuilder: vi.fn().mockImplementation(() => ({
setTitle: vi.fn().mockReturnThis(),
setDescription: vi.fn().mockReturnThis(),
setColor: vi.fn().mockReturnThis()
}))
};
});

// mocked interaction
type MockChatInputCommandInteraction = Pick<
ChatInputCommandInteraction,
"deferReply" | "editReply" | "user"
>;

let mockInteraction: MockChatInputCommandInteraction;

beforeEach(async () => {
vi.clearAllMocks();

await resetTestDatabase();

mockInteraction = {
deferReply: vi.fn().mockResolvedValue(undefined),
editReply: vi.fn().mockResolvedValue(undefined),
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
user: {
id: "123456789"
}
};
});
8 replies