我想为我的不和谐机器人发出一个serverinfo命令,并且我想建立一个显示角色数量和表情符号字段的字段。 有人可以告诉我该怎么做吗?
这是我的代码:
async runCommand(args: string[], msgObject: Discord.Message, client: Discord.Client): Promise<void> {
let embed = new Discord.RichEmbed()
.setColor("RANDOM")
.setTitle("Server Info")
.setImage(msgObject.guild.iconURL)
.setDescription(`${msgObject.guild}'s information`)
.addField("Owner", `The owner of this server is ${msgObject.guild.owner}`)
.addField("Member Count", `This server has ${msgObject.guild.memberCount} members`)
.addField("Emoji Count", `This server has ${msgObject.guild.emojis} emojis`)
.addField("Roles Count", `This server has ${msgObject.guild.roles} roles`)
msgObject.channel.send(embed)
.catch(console.error);
}
代码给了我这个
服务器信息
测试服务器的信息
所有者
此服务器的所有者为@ItamarD
会员人数 该服务器有3个成员
表情符号计数
此服务器具有[object Map]表情符号
角色数
此服务器具有[对象映射]角色
答案 0 :(得分:3)
如果查看Guild objects的Discord.js API文档,您会发现Guild.emojis和Guild.roles返回一个Collection。
Collection是Map的扩展,具有方便使用的size属性。
结果两行代码将是:
.addField("Emoji Count", `This server has ${msgObject.guild.emojis.size} emojis`)
.addField("Roles Count", `This server has ${msgObject.guild.roles.size} roles`)
答案 1 :(得分:0)
我的代码:
if(message.content.startsWith(":serveurinfo")) {
let si = new Discord.MessageEmbed()
.setColor("RANDOM")
.setTitle("Server Info")
.setDescription(`${message.guild.name}'s information`)
.addField("Owner", `The owner of this server is ${message.guild.owner}`)
.addField("Member Count", `This server has ${message.guild.memberCount} members`)
.addField("Emoji Count", `This server has ${message.guild.emojis.size} emojis`)
.addField("Roles Count", `This server has ${message.guild.roles.size} roles`)
message.channel.send(si);
}
对于表情符号和角色,答案是:该服务器具有未定义的表情符号,而该服务器具有未定义的角色
答案 2 :(得分:0)
只需使用
if(message.content.startsWith(":serveurinfo")) {
let si = new Discord.MessageEmbed()
.setColor("RANDOM")
.setTitle("Server Info")
.setDescription(`${message.guild.name}'s information`)
.addField("Owner", `The owner of this server is ${message.guild.owner}`)
.addField("Member Count", `This server has ${message.guild.memberCount} members`)
.addField("Emoji Count", `This server has ${message.guild.emojis.cache.size} emojis`)
.addField("Roles Count", `This server has ${message.guild.roles.cache.size} roles`)
message.channel.send(si);
}