I was doing this shop command for my discord server, and it’s suppose to show the shop items list one by one, but it’s not what’s happening, I don’t want it to reply the shop list with commas between the items, and I don’t know how to remove them, here is the code:
const { SlashCommandBuilder, EmbedBuilder} = require("discord.js");
const items = require("../shopitem")
const client = require("..");
module.exports = {
data: new SlashCommandBuilder()
.setName("shop")
.setDescription("See the avaliable items to buy!"),
async execute(interaction) {
if (items.lenght === 0) {
return await interaction.reply("There is no items here!", { ephemeral: true });
}
const shopList = items
.map((value) => {
return (`💵 ${value.price} - ${value.item}n`);
});
let embed_shop = new EmbedBuilder()
.setTitle("**🛒|** ***Store:***")
.setDescription(`${shopList}`)
.setThumbnail(interaction.user.displayAvatarURL())
.setTimestamp(Date.now())
.setAuthor({
name: interaction.user.username,
iconURL: interaction.user.displayAvatarURL({ dynamic: true }),
url: null
})
.setFooter({
iconURL: client.user.displayAvatarURL(),
url: null,
text: `Sistema exclusivo ${client.user.username}®`
})
.setColor("#FF0090");
await interaction.reply({ embeds : [embed_shop] });
},
};
when i use the command it replies the embed correctly but the shop list stay like this:
💵 100 – Backpack
,💵 500 – Radio
,💵 1000 – Smartphone
and i wanted it to be like this, withou commas:
💵 100 – Backpack
💵 500 – Radio
💵 1000 – Smartphone
i expect to find a simple way to remove these commas since i’ve never used .map, and it’s my first time doing this, i have no idea of how the function works, just the basic
2
Answers
In JS, when a array is converted to a string directly, it will join each item in the array with a comma (
,
). You can change this behavior by callingshopList.join("")
. That will insert an empty string between each item in the array and return a single string.You can also join using other strings to join as well, such as a newline (
n
), like this:shopList.join("n")
I think you want this
let me know if that’s not it