【问题标题】:Discord.js TypeError: Cannot read property 'size' of undefinedDiscord.js TypeError:无法读取未定义的属性“大小”
【发布时间】:2021-03-09 19:35:04
【问题描述】:

所以我正在尝试为我的机器人创建一个 stats 命令,但每当我运行该命令时,我都会不断收到以下错误:

TypeError: Cannot read property 'size' of undefined
    at Object.execute (C:\Users\jack\Bot\commands\stats.js:19:51)
    at module.exports (C:\Users\jack\Bot\events\message.js:44:13)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

这里是stats命令命令:

const {  MessageEmbed } = require("discord.js");
const moment = require("moment");
require("moment-duration-format");

module.exports = {
    name: "stats",
    aliases: ["botinfo"],
    description: "Says your input via the bot",
    usage: "<input>",
    execute(message, args, client) {
        const uptime = moment.duration(client.uptime).format("D [days], H [hrs], M [mins], S [secs]")
       
    const statsEmbed = new MessageEmbed()
        .addField('Uptime', uptime)
        .setThumbnail(
            client.user.displayAvatarURL({dynamic: true, size: 512})
            )
        .addField("Memory Usage", `${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)} MB`)
        .addField('Users', `${client.users.chache.size}`);

    message.channel.send(statsEmbed)
    }}

【问题讨论】:

    标签: node.js discord discord.js


    【解决方案1】:

    您输入了client.users.chache.size。正确的是client.users.cache.size

    你的问题:

    .addField('Users', `${client.users.chache.size}`);
                                        ^^^
    

    修复:

    .addField('Users', `${client.users.cache.size}`);
                                        ^^
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-14
      • 2020-07-14
      • 2019-07-11
      • 2021-05-29
      • 2020-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多