类型错误:无法读取未定义的属性“MessageEmbed”

时间:2021-05-18 09:51:12

标签: discord.js typeerror

我正在 Discord.js 中创建一个 Discord 机器人,我需要你的“+帮助”。 +help 命令将显示包含所有相关命令的嵌入。但是,当我进行嵌入时,出现此错误。

TypeError: Cannot read property 'MessageEmbed' of undefined

如果你好奇,这是我在 help.js 中的代码:

module.exports = {
    name: "help",
    description: "Help embed.",
    execute(message, args, Discord) {
        const Help = new Discord.MessageEmbed()
        .setColor("red")
        .setTitle("Command List")
        .setAuthor("Bots for Guilds")
        .setDescription("List of all commands with BFG software")
        .addFields (
            {name: "`+help`", value: "Shows all the commands."},
            {name: "`+ping`", value: "Ping-pong command: you write `+ping`, and the bot responds \"pong!\""},
            {name: "`+cheenta`", value: "Gives a link to my presentation at Cheenta Bose Olympiad Round 7."},
            {name: "`+whoisatharv`", value: "Gives information about me."},
            {name: "`+youtube`", value: "Give my YouTube Channel link."}
        );
        message.channel.send(Help);
    }
}

并且 help.js 正在使用命令处理程序连接到我的源文件 (main.js):

else if (command === "help") {
        client.commands.get("help").execute(message, args);
}

else if 是因为命令较多。)

你能帮我吗?

2 个答案:

答案 0 :(得分:0)

尝试只使用 MessageEmbed() 从执行中删除 Discord,就像这样

    module.exports = {
        name: "help",
        description: "Help embed.",
        execute(message, args) {
            const Help = new Discord.MessageEmbed()
            .setColor("red")
            .setTitle("Command List")
            .setAuthor("Bots for Guilds")
            .setDescription("List of all commands with BFG software")
            .addFields (
                {name: "`+help`", value: "Shows all the commands."},
                {name: "`+ping`", value: "Ping-pong command: you write `+ping`, and the bot responds \"pong!\""},
                {name: "`+cheenta`", value: "Gives a link to my presentation at Cheenta Bose Olympiad Round 7."},
                {name: "`+whoisatharv`", value: "Gives information about me."},
                {name: "`+youtube`", value: "Give my YouTube Channel link."}
            );
            message.channel.send(Help);
        }
    }

答案 1 :(得分:-1)

根据@Tyler2P 的评论,我在 Discordexecute() 函数中使用了 help.js 对象,但我没有在 client.commands.get().execute()main.js 中使用。< /p>