0

Code:

                 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] });
                    }
                });

Everything that I try to grab in the array where I declare mapped returns as undefined. How can I grab the data in the array?

The data from mongoose: Data from mongoose

1
  • Is the interaction guild you are using the bot exists in database? Commented Mar 19, 2022 at 0:32

1 Answer 1

1

Actually I just fixed it, happend to be as I posted this question. If anyone else is trying to find this out I ended up doing settings.roles[index]['(name of value u want to get here)']. In my case it was settings.roles[index]['emoji'] & settings.roles[index]['description']

Sign up to request clarification or add additional context in comments.

3 Comments

I'm fresh new about schema's but how'd you put items in object list?
To put it like that you would do something like roles: { stuff: here, more: here }
I always get like this when i do like that roles: { stuff: Object } idk why

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.