Discord.JS TypeError: Cannot read properties of undefined (reading 'get')

Discord.JS TypeError: Cannot read properties of undefined (reading 'get')

早上好!我目前正在开发一个 discord 机器人,但我遇到了 事件处理程序 的问题。 “get”命令似乎有问题,但我似乎无法找出问题所在 是的,我已经将下面的代码提供给我的 message.js

module.exports = (Discord, client, msg) => {

    const prefix = 'e!';

    if (!msg.content.startsWith(prefix) || msg.author.bot) return;

    const args = msg.content.slice(prefix.length).split(/ +/);
    const command = args.shift().toLowerCase();

    const cmd = client.commands.get(command)

    if (!cmd){
        msg.channel.send("That is not an available command!")
    };

    if(command) command.execute(client, msg, args, Discord);
};

下面的代码是我的index.js

const Discord = require("discord.js")
const client = new Discord.Client({intents : ["GUILDS", "GUILD_MESSAGES"]});
const button = require('discord-buttons')(client)
const { MessageButton } = require("discord-buttons")
 
client.commands = new Discord.Collection();
client.events = new Discord.Collection();

['command_handler', 'event_handler'].forEach(handler =>{
    require(`./handlers/${handler}`)(client, Discord);
})

client.login(process.env.token)

如有任何帮助,我们将不胜感激!

我修好了!好像Discord和客户端的顺序(在这里)。

module.exports = (Discord, client, msg)

错了!相反,我用 client 交换了 Discord,它似乎有效!

module.exports = (client, Discord, msg)

如果有人能告诉我为什么会这样(因为我很想了解更多) 您可以评论或回答!

执行命令也有错误,我也修复了

if(cmd) {
        cmd.execute(client, msg, args, Discord);
}

感谢大家的贡献!真的需要你的帮助!