我的 stats
命令有一个小问题,即使我做了嵌入属性也是未定义
。
if (command == "stats") {
let mcount = bot.users.size;
let scount = bot.guilds.size;
let tcount = bot.channels.filter(c => c.type === 'text').size;
let vcount = bot.channels.filter(c => c.type === 'voice').size;
let embed = new Discord.RichEmbed()
.setDescription(`:white_check_mark: Statistics of Tommy`)
.setColor("2c2f33")
.addField('**Users:**`' + `${mcount}` + '`')
.addField('**Servers:**`' + `${scount}` + '`')
.addField('**Text channels:**`' + `${tcount}` + '`')
.addField('**Voice channels:**`' + `${vcount}` + '`');
message.channel.send({
embed
});
}
最佳答案
您的示例大部分都有效,但它显示的值与字段名称位于同一行,并且 undefined
文本出现在每个字段名称下方。
原因是 addField
方法有第二个参数,用于设置字段名称下方的文本(或字段值)。
在您的示例中,对 addField 的调用可以更改为:
.addField('**Users:**', `${mcount}`)
.addField('**Servers:**', `${scount}`)
.addField('**Text channels:**', `${tcount}`)
.addField('**Voice channels:**', `${vcount}`)
我找到了this tutorial for RichEmbed and addField这帮助我理解了它的用法。
关于javascript - 统计命令显示嵌入中未定义的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53162543/