![](/img/trans.png)
[英]Discord.js collection; how to navigate and grab/count objects from an array in a collection
[英]How to grab data from an array in mongoose discord.js
代碼:
ReactionRole.findOne({ guild_id: interaction.guild.id }, (err, settings) => {
if (err) {
const embed = new MessageEmbed()
.setColor('RED')
.setTitle('Error:')
.setDescription(`An error occured while getting the reaction roles`)
.setTimestamp()
.setFooter({ text: `Phantom Bot v${config.version}` });
return interaction.reply({ embeds: [embed], ephemeral: true });
}
if (!settings) {
const embed = new MessageEmbed()
.setColor('RED')
.setTitle('Error:')
.setDescription(`There are no reaction roles for this guild`)
.setTimestamp()
.setFooter({ text: `Phantom Bot v${config.version}` });
return interaction.reply({ embeds: [embed], ephemeral: true });
} else {
const mapped = Object.keys(settings.roles).map((value, index) => {
return(`\`${index + 1}.\` ${settings.roles[2]} - ${settings.roles[1]}`)
}).join("\n\n");
const embed = new MessageEmbed()
.setColor('PURPLE')
.setTitle('Reaction Roles:')
.setDescription(`React with the emojis below to assign yourself a role`)
.addField('\u200B', `${mapped}`)
.setTimestamp()
.setFooter({ text: `Phantom Bot v${config.version}` });
channel.send({ embeds: [embed] });
}
});
我嘗試在聲明映射的數組中獲取的所有內容都返回未定義。 如何獲取數組中的數據?
實際上我剛剛修復它,恰好是我發布這個問題。 如果其他人試圖找到這個,我最終會做settings.roles[index]['(name of value u want to get here)']
。 在我的例子中是settings.roles[index]['emoji']
& settings.roles[index]['description']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.