类型错误:无法读取未定义的 discord.js 的属性“缓存”

时间:2021-03-30 23:09:39

标签: discord.js

嗨,当我试图让它发布服务器计数和它返回的其他东西时,我有一些缓存的botter

    B:\stuff\Downloads\Admeeeeeen bot\src\commands\info\stats.js:27
        { name: 'Server Count:', value: `${client.guilds.cache.size}`, inline: true },
                                                         ^
TypeError: Cannot read property 'cache' of undefined

 run(message, client, guild) {
    const d = moment.duration(message.client.uptime);
    const days = (d.days() == 1) ? `${d.days()} day` : `${d.days()} days`;
    const hours = (d.hours() == 1) ? `${d.hours()} hour` : `${d.hours()} hours`;
    const minutes = (d.minutes() == 1) ? `${d.minutes()} minute` : `${d.minutes()} minutes`;
    const seconds = (d.seconds() == 1) ? `${d.seconds()} second` : `${d.seconds()} seconds`;
    const prefix = message.client.db.settings.selectPrefix.pluck().get(message.guild.id);
    
    const embed = new MessageEmbed()
    .setTitle('__Admeeeeeen bot\'s Bot Information__')
    .addFields(
        { name: 'Server Count:', value: `${client.guilds.cache.size}`, inline: true },
        { name: 'Uptime:', value: `${days}, ${hours}, ${minutes}, and ${seconds}`, inline: true },
    )
      .setThumbnail('https://imgur.com/aaX76bI.png')
      .setFooter(message.member.displayName,  message.author.displayAvatarURL({ dynamic: true }))
      .setTimestamp()
      .setColor(message.guild.me.displayHexColor);
    message.channel.send(embed);
    console.log(guild) 

  }
}

1 个答案:

答案 0 :(得分:1)

您已将 client 定义为第二个参数,请尝试使用 message.client.guilds.cache.size,并且您不需要额外的参数,那么代码将类似于

run(message) {
   .
   { name: 'Server Count:', value: `${message.client.guilds.cache.size}`, inline: true },
   .
}