我是 Typescript 的新手,并使用 Typescript 编写了一个 Discord 机器人。我想向客户端对象添加一个变量“命令”。例如在 Javascript 中,你使用这个:
Javascript
const { Client } = require('discord.js');
const client = new Client();
client.commands = 'commands';
console.log(client.commands);
// 'commands'
但现在我想添加类似于 Typescript 的内容。但是当我在 Typescript 中使用它时,出现以下错误:
Property 'commands' does not exist on type 'Client'.ts(2339)
我该如何解决这个问题?
我目前的代码:
export class HalloClient {
private client: Client;
constructor() {
this.client = new Client();
this.client.commands = new Collection();
}
public start(): void {
console.log(`- Client | Starting process...`);
new RegisterEvents('../events/', this.client).load();
new MongoConnection(process.env.mongouri).createConnection();
console.log(this.client);
this.client.login(process.env.token);
}
}
白板的微信
相关分类