mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 12:03:31 +01:00
fix(guide): Show rest of TypeScript code block (#9465)
This commit is contained in:
@@ -26,13 +26,12 @@ Now that your command files have been created, your bot needs to load these file
|
|||||||
|
|
||||||
In your _`index.js`_ file, make these additions to the base template:
|
In your _`index.js`_ file, make these additions to the base template:
|
||||||
|
|
||||||
<CH.Code rows={14}>
|
<CH.Code>
|
||||||
|
|
||||||
```js JavaScript focus=1:3,9
|
```js JavaScript mark=1:4,9
|
||||||
import { readdir } from 'node:fs/promises';
|
import { readdir } from 'node:fs/promises';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
// focus[18:28]
|
|
||||||
import { Client, Collection, Events, GatewayIntentBits } from 'discord.js';
|
import { Client, Collection, Events, GatewayIntentBits } from 'discord.js';
|
||||||
import config from './config.json' assert { type: 'json' };
|
import config from './config.json' assert { type: 'json' };
|
||||||
|
|
||||||
@@ -45,12 +44,18 @@ client.once(Events.ClientReady, () => {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
```ts TypeScript focus=1:3,9:14
|
```ts TypeScript mark=1:11,16:21
|
||||||
import { readdir } from 'node:fs/promises';
|
import { readdir } from 'node:fs/promises';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
// focus[18:28]
|
import {
|
||||||
import { Client, Collection, Events, GatewayIntentBits } from 'discord.js';
|
Client,
|
||||||
|
Collection,
|
||||||
|
Events,
|
||||||
|
GatewayIntentBits,
|
||||||
|
type RESTPostAPIChatInputApplicationCommandsJSONBody,
|
||||||
|
type ChatInputCommandInteraction,
|
||||||
|
} from 'discord.js';
|
||||||
import config from './config.json';
|
import config from './config.json';
|
||||||
|
|
||||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||||
@@ -259,11 +264,11 @@ for (const folder of commandFolders) {
|
|||||||
const commands = new Collection<string, CommandModule>();
|
const commands = new Collection<string, CommandModule>();
|
||||||
|
|
||||||
const foldersPath = fileURLToPath(new URL('commands', import.meta.url));
|
const foldersPath = fileURLToPath(new URL('commands', import.meta.url));
|
||||||
const commandFolders = readdir(foldersPath);
|
const commandFolders = await readdir(foldersPath);
|
||||||
|
|
||||||
for (const folder of commandFolders) {
|
for (const folder of commandFolders) {
|
||||||
const commandsPath = join(foldersPath, folder);
|
const commandsPath = join(foldersPath, folder);
|
||||||
const commandFiles = readdir(commandsPath).then((files) => files.filter((file) => file.endsWith('.js')));
|
const commandFiles = await readdir(commandsPath).then((files) => files.filter((file) => file.endsWith('.js')));
|
||||||
for (const file of commandFiles) {
|
for (const file of commandFiles) {
|
||||||
const filePath = join(commandsPath, file);
|
const filePath = join(commandsPath, file);
|
||||||
const command = await import(filePath);
|
const command = await import(filePath);
|
||||||
|
|||||||
Reference in New Issue
Block a user