【问题标题】:TypeError: Cannot read property 'MessageEmbed' of undefinedTypeError:无法读取未定义的属性“MessageEmbed”
【发布时间】:2021-08-07 13:15:45
【问题描述】:

我正在 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是因为有更多的命令。)

你能帮帮我吗?

【问题讨论】:

  • 欢迎来到 SO。出于好奇,当您询问“+help”(或任何语法)时,是否有任何参数?如果没有参数,我猜该消息将为空。
  • @ewong 没有参数。我清楚地看到“未定义”来自Discord 对象。
  • 您需要实际定义Discord。在help.js中插入const Discord = require('discord.js');或在执行文件时定义Discord。
  • @Tyler2P 我在文件main.js中有它。
  • 在这种情况下,使用client.commands.get("help").execute(message, args, Discord);

标签: discord.js typeerror


【解决方案1】:

尝试只使用 MessageEmbed() 从执行中删除不和谐,就像

    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);
        }
    }

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2021-01-18
      • 2021-04-18
      • 2020-09-22
      • 2021-10-03
      • 1970-01-01
      • 2020-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多