javascript - 我正在尝试在 discord.js 中进行嵌入,但它不断给出错误
问题描述
module.exports = {
name: 'clear',
description: "Clears a select amount of messages",
execute(message, args, Discord, amount=5){
const newEmbed = new Discord.MessageEmbed()
.setColor('#304281')
.setTitle('Not enough power!')
.setDescription('')
.addFields(
{name: '', value: 'You dont have the required permission to use this command'}
)
.setFooter('More Coming Soon!');
if(message.member.permissions.has("MANAGE_MESSAGES" || "ADMINISTRATOR")){
message.channel.send('this should clear messages lol')
} else {
channel.send(newEmbed);
}
}
}
那是我尝试嵌入的代码。我不断收到的错误是:
“const newEmbed = 新的 Discord.MessageEmbed()
TypeError:无法读取未定义的属性“MessageEmbed”
任何帮助将不胜感激
解决方案
正如错误所暗示的,没有MessageEmbed
undefined 的属性,这意味着 Discord 是未定义的。在文件的最顶部,在 上方module.exports = {
,只需添加行const Discord = require('discord.js');
.
即使您在主文件中导入了不和谐,您也没有在此文件中执行此操作,因此在该文件中未定义。在文件的最顶部添加该行会将其导入该文件,并且可以在文件中的任何位置使用。希望对您有所帮助。
推荐阅读
- java - 如何执行一项任务并每分钟返回一个数据
- android - Firebase-ML Kit 库无法检测三星 J5 设备中的条形码
- elixir - 有没有办法从凤凰通道来回调用控制器方法
- javascript - 是否可以使用 jquery: on 方法在文档中动态加载的 iframe 内容上触发事件
- java - 如何在 Android Studio 中找到 Activity.runOnUiThread 覆盖的内容?
- javascript - IE 11 Javascript 正则表达式替换错误地替换元字符
- jenkins - Jenkins 输入管道步骤 - 将提交者作为本地组
- nuget - Nuget packages.config - 第 3 方 dll 不会复制到输出目录
- java - 为每 5 个项目在 recyclerview 中放置广告?
- android - Android如何在折叠工具栏布局中添加带有两个文本视图的图像视图