【发布时间】:2021-03-23 11:21:42
【问题描述】:
我有一个 discord.js 调平系统,它将人们的关卡存储在一个 json 文件 database.json 中,如下所示:{"626916199783071750":{"xp":54,"level":14}我正在使用此代码对每个人的关卡进行排序:
members.sort(function(a, b) {
const keyA = a[Object.keys(a)[0]].level,
keyB = b[Object.keys(a)[0]].level;
// Compare
// (swap -1 and 1 to change sort order)
if(keyA < keyB) return -1;
if(keyA > keyB) return 1;
return 0;
});
console.log(members);
(成员被定义为const members = [require("./database.json")];)
我能够很好地记录它并且它的顺序正确,但我想知道如何将它发送到嵌入中,因为此代码不起作用:
let embed = new Discord.RichEmbed()
.setColor(0x4286f4)
.addField('Level:', members)
member.channel.send(embed);
这给了我一个带有未定义字段的嵌入。 作为参考,我正在使用 discord.js v12+
【问题讨论】:
-
应该是
new Discord.MessageEmbed(),因为你使用的是 Discord.js 的 v12 -
现在我得到
TypeError: Cannot read property 'client' of undefined -
我认为它是由其他地方引起的,请检查引起错误的行号。
-
我不相信 discord.js 允许您直接将嵌入字段或消息内容设置为数组/对象。在将数组添加到嵌入字段之前,您需要将其转换为字符串。至于
Cannot read property 'client' of undefined,该错误与此问题无关,完全在您代码中的其他位置。 -
它说它发生在
let embed = new Discord.RichEmbed()的代码行上
标签: javascript node.js discord.js