Haven
Haven
DIAdiscord.js - Imagine an app
Created by Haven on 4/18/2024 in #djs-questions
fs.readdir, glob, fast-glob all won't match any files while using Typescript
async getEvents() {
const eventPath = path.join(__dirname, "events");
fs.readdir(eventPath, async (err, files) => {
if (err) throw err;
let eventCount = 0;
for (const filePath of files) {
const event: Event<keyof ClientEvents> =
await this.importFile(filePath);
this.on(event.event, event.execute);
}
});
}
async getEvents() {
const eventPath = path.join(__dirname, "events");
fs.readdir(eventPath, async (err, files) => {
if (err) throw err;
let eventCount = 0;
for (const filePath of files) {
const event: Event<keyof ClientEvents> =
await this.importFile(filePath);
this.on(event.event, event.execute);
}
});
}
[Error: ENOENT: no such file or directory, scandir 'F:\...\dist\events'] {
errno: -4058,
code: 'ENOENT',
syscall: 'scandir',
path: 'F:\\...\\dist\\events'
}
[Error: ENOENT: no such file or directory, scandir 'F:\...\dist\events'] {
errno: -4058,
code: 'ENOENT',
syscall: 'scandir',
path: 'F:\\...\\dist\\events'
}
Directory Setup:
project root
dist/
node_modules/
src/
commands/
...
events/
interactionCreate.ts
...
structures/
Client.ts
...
index.ts
package.json
...
project root
dist/
node_modules/
src/
commands/
...
events/
interactionCreate.ts
...
structures/
Client.ts
...
index.ts
package.json
...
Client.ts is the file from the snippet. Here's my tsconfig
{
"compilerOptions": {
"lib": ["ES2021"],
"target": "ES2021",
"module": "commonjs",
"moduleResolution": "Node",
"outDir": "dist",
"sourceMap": false,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"skipDefaultLibCheck": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"strict": true
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}
{
"compilerOptions": {
"lib": ["ES2021"],
"target": "ES2021",
"module": "commonjs",
"moduleResolution": "Node",
"outDir": "dist",
"sourceMap": false,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"skipDefaultLibCheck": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"strict": true
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}
22 replies
DIAdiscord.js - Imagine an app
Created by Haven on 4/17/2024 in #djs-questions
Extending Client and making Interaction.client use that new Client
As said in the guide, I have extended my Client class, no problems there. Though, I want to use interaction.client in my commands, yet that still refers to the old class. Forgive me, I'm a little new to JS and absolutely not sure how to go about this, am I thinking of it wrong even? Should I be passing client in my command handler? Should I just use imports? I would really like to avoid the imports, but I'm not against it. What is the right choice here, I'm almost positive I cannot be the first to ask this question, but a search yields no results here.
6 replies