【发布时间】: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