【发布时间】:2021-11-04 12:36:35
【问题描述】:
src/index.d.ts:
declare module "discord.js" {
export interface Client {
commands: import('discord.js').Collection<unknown, Command>,
handleEvents(eventFiles: string[], path: string): any,
handleCommands(eventFiles: string[], path: string): any,
commandArray: any
}
export interface Command {
name: string,
description: string,
execute: (message: import('discord.js').Message, args?: string[]) => Promise<Command> // Can be `Promise<SomeType>` if using async
}
}
export {}
每当我使用它时,当我使用.handleCommands 和.handleEvents 时,我会得到:
“typeof Client”类型上不存在属性“handleCommands”
我在这里尝试使用它src/index.ts
import DiscordJS, { Intents, Collection, Client } from 'discord.js'
import fs from 'fs'
require('dotenv').config();
export const client: Client = new DiscordJS.Client({ intents: [Intents.FLAGS.GUILDS] });
client.commands = new Collection();
const functions = fs.readdirSync('./src/functions').filter((file: string) => file.endsWith('.ts'));
const eventFiles = fs.readdirSync('./src/events').filter((file: string) => file.endsWith('.ts'));
const commandFolders = fs.readdirSync('./src/commands').filter((file: string) => file.endsWith('.ts'));
(async () => {
for (const file of functions) {
require(`./functions/${file}`)(client);
}
client.handleEvents(eventFiles, './src/events');
client.handleCommands(commandFolders, './src/commands');
client.login(process.env.TOKEN);
})
请帮助我,我不知道我还能做什么。
【问题讨论】:
-
出于好奇
Client#commands有效吗? -
CLient#commands in import?
标签: typescript discord.js