【问题标题】:Warning: Property commands is not defined in type module:"discord.js".Client警告:类型模块中未定义属性命令:“discord.js”.Client
【发布时间】:2020-11-16 04:14:26
【问题描述】:

我的代码有效,但我收到此警告,是否有更好的做法来定义 Discord.js 客户端的属性命令?

Warning: Property commands is not defined in type module:"discord.js".Client   
const Discord = require('discord.js');

const client = new Discord.Client();
const Enmap = require("enmap");
client.commands = new Enmap();

const init = async () => {
    fs.readdir("./commands/",(err,files) =>{
        if (err) return console.error(err);
        files.forEach(file => {
            if (!file.endsWith(".js")) return;
            const command = require(`./commands/${file}`);
            let commandName = file.split(".")[0];
            console.log(`Attempting to load command ${commandName}`);
            client.commands.set(commandName,command)
        });
    });
};

【问题讨论】:

    标签: javascript discord discord.js


    【解决方案1】:

    您不能定义 commands 属性。您可以在此处的文档中找到客户端:client。代码有效,因为您将 client.commands 设置为 Enmap,但没有它,client.commands 会使代码崩溃。

    【讨论】:

      猜你喜欢
      • 2020-12-15
      • 1970-01-01
      • 1970-01-01
      • 2021-06-07
      • 2021-06-02
      • 2014-09-08
      • 2021-07-04
      • 2020-05-30
      • 1970-01-01
      相关资源
      最近更新 更多