I’m trying to make a shop command that lists the items that I have added to the shop via another command. I tried to use a for loop to add to the string, but I had no luck with that because the values were undefined For some reason. At this point, I’ve switched to forEach in an attempt to try and make this work, but instead of each value being undefined, it only lists 1 of the 2 items saved in the database.
I am using Enmap to store the shop items.
I filter the shop items using the .filter() function which returns an Enmap (map)
Expected Behavior: The command properly lists all items in the shop (in this case 2 items) and all of their values
Actual Behavior: The embed only shows 1/2 of the items.
const Discord = require('discord.js');
module.exports = {
id: 'shop',
aliases: ['buythings', 'linkcoinshop', 'edward'],
channels: 'guild',
exec: async (call) => {
try {
let filter = await call.client.shopData.filter(find => {
return find.guildID === call.message.guild.id && find.forSale === true
});
if(filter.size === 0) return call.message.channel.send(`There are no items for sale right now.`)
let embedDesc = '';
console.log(filter)
filter.forEach(found => {
embedDesc += `**__${found.itemName}__** \nDescription: ${found.itemDesc} \nCost: ${found.itemCost} \nQuantity: ${found.itemQuan} \n\n`
})
const linkCoin = call.client.emojis.get('670675326837194782');
const shopEmbed = new Discord.RichEmbed()
.setTitle(`${linkCoin} LinkCoins Shop`)
.setColor('BLURPLE')
.setDescription(embedDesc);
//.setDescription(`🔷: **__Diamond Role__** \nDescription: Gives access to diamond only perks including special giveaways and more! \nCost: 1500${linkCoin} \nQuantity: ♾️ \n\n 💠: **__Diamond + Role__** \nDescription: Access to all perks that Diamond gets you, but with extra abilities such as your own personal voice chats. \n`)
call.message.channel.send(`Click on the reactions below to purchase.`)
call.message.channel.send(shopEmbed)
} catch(error) {
call.message.channel.send(`Oops! That was an error! The issue has been reported to the adminstration team`);
console.log(error);
}
}
};
If anybody has any suggestions of a better way to do this, or just a way to make this work, please let me know. Thanks!