Javascript I';我在Discord.js中遇到了诸如client.users.cache.size等函数的问题

Javascript I';我在Discord.js中遇到了诸如client.users.cache.size等函数的问题,javascript,node.js,discord.js,Javascript,Node.js,Discord.js,每当我尝试使用诸如client.users.cache.size或client.guilds.size之类的函数时,他们总是给我一个错误,如“TypeError:无法读取未定义的属性'guilds'”或“TypeError:无法读取未定义的属性'cache' 我还尝试使用让guilds=client.guilds.cache.array().join('\n'),但它也会引发相同的错误 命令代码: const Discord=require('Discord.js'); module.expor

每当我尝试使用诸如
client.users.cache.size
client.guilds.size
之类的函数时,他们总是给我一个错误,如“TypeError:无法读取未定义的属性'guilds'”或“TypeError:无法读取未定义的属性'cache'

我还尝试使用
让guilds=client.guilds.cache.array().join('\n')
,但它也会引发相同的错误

命令代码:

const Discord=require('Discord.js');
module.exports={
名称:'统计',
description:'查看机器人的统计信息',
执行(客户端、消息){
const embed=new Discord.MessageEmbed
.setDescription(`In${client.guilds.size}服务器`)
.setTimestamp()文件
.setFooter(message.member.user.tag,message.author.avatarURL());
message.channel.send(嵌入)
}
}
Bot的主文件:

const path=require('path');
常数fs=要求(“fs”);
const{token,prefix}=require('./config.json');
const Discord=require('Discord.js');
const db=require('quick.db');
const client=new Discord.client
client.commands=new Discord.Collection();
const isDirectory=source=>fs.lstatSync(source.isDirectory();
const getDirectories=source=>fs.readdirSync(source).map(name=>path.join(source,name)).filter(isDirectory);
GetDirectory(uuu dirname+'/commands')。forEach(类别=>{
const commandFiles=fs.readdirSync(category.filter)(file=>file.endsWith('.js'));
for(命令文件的常量文件){
const command=require(`${category}/${file}`);
client.commands.set(command.name,command);
}
});
client.on(“ready”,()=>{
log(`ready!。`);
console.log(令牌);
//活动
常数活动列表=[
`提供墨西哥玉米卷。救命,
`准备订单|。帮助`
];
设置间隔(()=>{
const index=Math.floor(Math.random()*(activities_list.length-1)+1);
client.user.setActivity(activities_list[index]);
}, 10000);
});
//加入公会
client.on(“guildCreate”,(guild)=>{
const EmbedJoin=new Discord.MessageEmbed()
.setColor(“#FFFF33”)
.setTitle(`Joined Guild:${Guild.name}!`)
.setTimestamp()文件
log(`Joined New Guild:${Guild.name}`);
client.channels.cache.get(`746423099871985755`).发送(EmbedJoin)
});
//左派
client.on(“guildelete”,(guild)=>{
const EmbedLeave=new Discord.MessageEmbed()
.setColor(“#FFFF33”)
.setTitle(`Left Guild:${Guild.name}.`)
.setTimestamp()文件
log(`Left Guild:${Guild.name}`);
client.channels.cache.get(`746423099871985755`)。send(EmbedLeave)
});
client.on('message',message=>{
如果(!message.content.startsWith(prefix)| | message.author.bot)返回;
const args=message.content.slice(prefix.length.trim().split(+/);
const commandName=args.shift().toLowerCase();
const command=client.commands.get(commandName)
||client.commands.find(cmd=>cmd.aliases&&cmd.aliases.includes(commandName));
如果(!命令)返回;
if(command.guildOnly&&message.channel.type=='dm'){
returnmessage.reply('我无法在DMs内部执行该命令!');
}
if(command.args&&!args.length){
let reply=`${message.author},用法错误`;
if(命令用法){
reply+=`\n正确的用法是:\`${prefix}${command.name}${command.usage}\`;
}
返回消息.channel.send(应答);
}
试一试{
执行(消息,参数);
}捕获(错误){
控制台错误(error);
message.reply('尝试执行该命令时出错!');
}
});
process.on(“错误”,()=>{
log(“糟糕,发生了什么事!”);
});
client.login(令牌);

在代码中,
client.guilds
返回一个管理器,因此必须使用
client.guilds.cache.size
。代码的其余部分工作正常

const Discord=require('Discord.js');
module.exports={
名称:'统计',
description:'查看机器人的统计信息',
执行(消息、参数、客户端){
const embed=new Discord.MessageEmbed
.setDescription(`In${client.guilds.cache.size}servers`)
.setTimestamp()文件
.setFooter(message.member.user.tag,message.author.avatarURL());
message.channel.send(嵌入)
}
}
在主bot文件中,您只将
消息
参数
(按此顺序)传递给
命令。execute()
。您也可以添加
客户端
,并更新命令代码中的参数以匹配此顺序

试试看{
执行(消息、参数、客户端);
}捕获(错误){
...
}

您需要编辑您的问题并添加一些代码,这样我们就可以看到什么不起作用了。好的,我编辑了它。它给了我一个错误“TypeError:无法读取未定义的属性‘cache’”。如何调用
execute()
方法?是
client
新的Discord.client()
消息
传入消息?是的,正如您所说的
客户端
新的不和谐。客户端
和消息是
客户端。on('message',message=>{
如果有帮助的话,我可以用主文件的完整代码编辑我的帖子。这可能会有帮助。虽然不确定我是否能在接下来的几个小时内检查它,但我会尝试。好的,我编辑了它,谢谢你的时间