TypeError:无法读取未定义的属性“ RichEmbed”

时间:2020-06-01 05:19:56

标签: node.js discord.js

我一直在寻找此错误的解决方案,但直到现在我还没有找到任何解决方案,现在花了2天多的时间才能找到解决方案,所以我在这里发布了我的问题,因此任何人都可以看到并评论为什么错误显示?

问题: TypeError: Cannot read property 'RichEmbed' of undefined(18:35)

我的代码

1:  module.exports.run = async (bot, message, args) => {
2: 
3:      let target = message.guild.member(message.mentions.users.first());
4:      let reason = args.slice(1).join(' ');
5:      let logs = message.guild.channels.cache.find(channel => channel.name === "⚠server_logs");
6:    
7:      // member.guild.channels.cache.find('⚠server_logs', config.logsChannel);
8:
9:      if (!message.member.hasPermission('BAN_MEMBERS')) return message.reply('you don\'t have permissions to use this command!s');
10:
11:      if (!target) return message.reply('please specify a member to ban!');
12:      if (!reason) return message.reply('please specify a reason for this ban!');
13:      if (!logs) return message.reply(`please create a channel called ${config.logsChannel} to log the bans!`);
14:
15:      let embed = new discord.cache.RichEmbed()
16:          .setColor('RANDOM')
17:          .setThumbnail(target.user.avatarURL)
18:          .addField('Banned Member', `${target.user.username} with an ID: ${target.user,id}`)
19:          .addField('Banned By', `${message.author.username} with an ID: ${message.author.id}`)
20:          .addField('Banned Time', message.createdAt)
21:          .addField('Banned At', message.channel)
22:          .addField('Banned Reason', reason)
23:          .addFooter('Banned user information', target.user.displayAvatarURL);
24:
25:      message.channel.send(`${target.user.username} was banned by ${message.author} for ${reason}`);
26:      target.ban(reason);
27:      logs.send(embed);
28:  };

3 个答案:

答案 0 :(得分:0)

尝试一下:

const { RichEmbed } = require ('discord.js');

module.exports.run = async (bot, message, args) => {

let target = message.guild.member(message.mentions.users.first());
let reason = args.slice(1).join(' ');
let logs = message.guild.channels.cache.find(channel => channel.name === "⚠server_logs");

// member.guild.channels.cache.find('⚠server_logs', config.logsChannel);

if (!message.member.hasPermission('BAN_MEMBERS')) return message.reply('you don\'t have permissions to use this command!s');

if (!target) return message.reply('please specify a member to ban!');
if (!reason) return message.reply('please specify a reason for this ban!');
if (!logs) return message.reply(`please create a channel called ${config.logsChannel} to log the bans!`);

let embed = new RichEmbed()
.setColor('RANDOM')
.setThumbnail(target.user.avatarURL)
.addField('Banned Member', `${target.user.username} with an ID: ${target.user,id}`)
.addField('Banned By', `${message.author.username} with an ID: ${message.author.id}`)
.addField('Banned Time', message.createdAt)
.addField('Banned At', message.channel)
.addField('Banned Reason', reason)
.addFooter('Banned user information', target.user.displayAvatarURL);

message.channel.send(`${target.user.username} was banned by ${message.author} for ${reason}`);
target.ban(reason);
logs.send(embed);
};

答案 1 :(得分:0)

您似乎没有定义discord.cache。 如果您使用的是discord.js v12或更高版本,请使用Discord.MessageEmbed()。如果使用v11,请使用Discord.RichEmbed()

确保添加

const Discord = require("discord.js");

在顶部。

示例

const Discord = require("discord.js"); // v12
let embed = new Discord.MessageEmbed()
.setColor("RED")
.setTitle("This is an embed.");

答案 2 :(得分:0)

您的代码有两个问题: 第一个是未定义不和谐, 并且RichEmbed在v12中被MessageEmbed取代,因此您应该将其添加到代码顶部:

const discord = require('discord.js'); // defines discord.js

,如果您使用的是discord.js v12,则将“ new discord.cache.RichEmbed()”替换为:

let embed = new discord.MessageEmbed(); // define the embed you want to use