Javascript 无法从Discord JS中的事件侦听器访问我的扩展客户端

Javascript 无法从Discord JS中的事件侦听器访问我的扩展客户端,javascript,node.js,discord,discord.js,Javascript,Node.js,Discord,Discord.js,假设我有以下代码: 类CustomClient扩展了客户端{ 建造师(数据){ 超级(数据); this.customProperty=“hello”; } } const client=新客户机(/*props*/); on('message',message=>{//message是message类的一个实例 console.log(message.client instanceof CustomClient)//false console.log(message.client instan

假设我有以下代码:

类CustomClient扩展了客户端{
建造师(数据){
超级(数据);
this.customProperty=“hello”;
}
}
const client=新客户机(/*props*/);
on('message',message=>{//message是message类的一个实例
console.log(message.client instanceof CustomClient)//false
console.log(message.client instanceof client)//true
console.log(message.client.customProperty)//未定义
});
显然,收到的消息(和其他discordjs事件)没有链接到CustomClient


是否有一种方法可以“扩展”默认的
Client
类,以便
CustomClass.Client
存在?

要使用该类,需要对其进行初始化

class CustomClient extends Client{
  constructor (options){
      super(options)
    this.customProperty = "hello";
  }
}
var CustomClient = new CustomClient()
CustomClient.on(...) 
我认为您需要在类中调用构造函数。以下工作将起作用:

类CustomClient扩展了客户端{
建造师(道具){
超级(道具);
this.customProperty='hello';
}
}
const client=new CustomClient();
client.on('消息',(消息)=>{
console.log(message.client instanceof CustomClient);//true
console.log(message.client instanceof client);//true
console.log(message.client.customProperty);//您好
});

哦,你比我快31秒。请让我投票:)谢谢你的回答。但是,我忘了提到我已经在使用
super
调用基类。另外,我的客户端已经初始化(我更新了帖子),因为我对Cursed的答案发表了评论,我忘了提到我正在使用super,并且已经创建了一个实例(客户端就是实例),这很奇怪,因为我测试了上述代码,它运行良好。您发布的当前代码对我来说运行良好: