Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Command } from '../index.ts';

export default {
data: {
name: 'user',
description: 'Provides information about the user.',
},
async execute(interaction) {
await interaction.reply(`This command was run by ${interaction.user.username}.`);
},
} satisfies Command;
18 changes: 10 additions & 8 deletions packages/create-discord-bot/template/Deno/src/util/loaders.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PathLike } from 'node:fs';
import { readdir, stat } from 'node:fs/promises';
import { URL } from 'node:url';
import { fileURLToPath, URL } from 'node:url';
import type { Command } from '../commands/index.ts';
import { predicate as commandPredicate } from '../commands/index.ts';
import type { Event } from '../events/index.ts';
Expand Down Expand Up @@ -40,22 +40,24 @@ export async function loadStructures<T>(

// Loop through all the files in the directory
for (const file of files) {
// If the file is index.js or the file does not end with .js, skip the file
if (file === 'index.ts' || !file.endsWith('.ts')) {
continue;
}
const fileUrl = new URL(`${dir}/${file}`, import.meta.url);

// Get the stats of the file
const statFile = await stat(new URL(`${dir}/${file}`));
const statFile = await stat(fileUrl);

// If the file is a directory and recursive is true, recursively load the structures in the directory
if (statFile.isDirectory() && recursive) {
structures.push(...(await loadStructures(`${dir}/${file}`, predicate, recursive)));
structures.push(...(await loadStructures(fileUrl, predicate, recursive)));
continue;
}

// If the file is index.ts or the file does not end with .ts, skip the file
if (file === 'index.ts' || !file.endsWith('.ts')) {
continue;
}

// Import the structure dynamically from the file
const structure = (await import(`${dir}/${file}`)).default;
const structure = (await import(fileURLToPath(fileUrl))).default;

// If the structure is a valid structure, add it
if (predicate(structure)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import('../index.js').Command} */
export default {
data: {
name: 'user',
description: 'Provides information about the user.',
},
async execute(interaction) {
await interaction.reply(`This command was run by ${interaction.user.username}.`);
},
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readdir, stat } from 'node:fs/promises';
import { URL } from 'node:url';
import { fileURLToPath, URL } from 'node:url';
import { predicate as commandPredicate } from '../commands/index.js';
import { predicate as eventPredicate } from '../events/index.js';

Expand Down Expand Up @@ -37,22 +37,24 @@ export async function loadStructures(dir, predicate, recursive = true) {

// Loop through all the files in the directory
for (const file of files) {
// If the file is index.js or the file does not end with .js, skip the file
if (file === 'index.js' || !file.endsWith('.js')) {
continue;
}
const fileUrl = new URL(`${dir}/${file}`, import.meta.url);

// Get the stats of the file
const statFile = await stat(new URL(`${dir}/${file}`));
const statFile = await stat(fileUrl);

// If the file is a directory and recursive is true, recursively load the structures in the directory
if (statFile.isDirectory() && recursive) {
structures.push(...(await loadStructures(`${dir}/${file}`, predicate, recursive)));
structures.push(...(await loadStructures(fileUrl, predicate, recursive)));
continue;
}

// If the file is index.js or the file does not end with .js, skip the file
if (file === 'index.js' || !file.endsWith('.js')) {
continue;
}

// Import the structure dynamically from the file
const structure = (await import(`${dir}/${file}`)).default;
const structure = (await import(fileURLToPath(fileUrl))).default;

// If the structure is a valid structure, add it
if (predicate(structure)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Command } from '../index.[REPLACE_IMPORT_EXT]';

export default {
data: {
name: 'user',
description: 'Provides information about the user.',
},
async execute(interaction) {
await interaction.reply(`This command was run by ${interaction.user.username}.`);
},
} satisfies Command;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PathLike } from 'node:fs';
import { readdir, stat } from 'node:fs/promises';
import { URL } from 'node:url';
import { fileURLToPath, URL } from 'node:url';
import type { Command } from '../commands/index.[REPLACE_IMPORT_EXT]';
import { predicate as commandPredicate } from '../commands/index.[REPLACE_IMPORT_EXT]';
import type { Event } from '../events/index.[REPLACE_IMPORT_EXT]';
Expand Down Expand Up @@ -40,22 +40,24 @@ export async function loadStructures<T>(

// Loop through all the files in the directory
for (const file of files) {
// If the file is index.[REPLACE_IMPORT_EXT] or the file does not end with .[REPLACE_IMPORT_EXT], skip the file
if (file === 'index.[REPLACE_IMPORT_EXT]' || !file.endsWith('.[REPLACE_IMPORT_EXT]')) {
continue;
}
const fileUrl = new URL(`${dir}/${file}`, import.meta.url);

// Get the stats of the file
const statFile = await stat(new URL(`${dir}/${file}`));
const statFile = await stat(fileUrl);

// If the file is a directory and recursive is true, recursively load the structures in the directory
if (statFile.isDirectory() && recursive) {
structures.push(...(await loadStructures(`${dir}/${file}`, predicate, recursive)));
structures.push(...(await loadStructures(fileUrl, predicate, recursive)));
continue;
}

// If the file is index.[REPLACE_IMPORT_EXT] or the file does not end with .[REPLACE_IMPORT_EXT], skip the file
if (file === 'index.[REPLACE_IMPORT_EXT]' || !file.endsWith('.[REPLACE_IMPORT_EXT]')) {
continue;
}

// Import the structure dynamically from the file
const structure = (await import(`${dir}/${file}`)).default;
const structure = (await import(fileURLToPath(fileUrl))).default;

// If the structure is a valid structure, add it
if (predicate(structure)) structures.push(structure);
Expand Down