#Variable ActionRowBuilder Options

15 messages · Page 1 of 1 (latest)

rough tide
#

is there any way for me to make the addOptions section of a SelectMenuBuilder variable? I have a command that lists the users that have been in the server for over 24 hours and I want to add them all to a list of users to kick, but that list could be anywhere from like 1 user to like 20.

south gullBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

candid marsh
#

yes, you can call the addOptions multiple times

rough tide
candid marsh
#

yes, exactly the same way you know who to kick

rough tide
candid marsh
#

and?

rough tide
#

If I map addOptions will it add a new option for every user?

candid marsh
#

yes, map runs the function you pass for every element (and returns an array of results of each call)

#

if you call addOptions inside of that map, it will run for every element in the array/collection

rough tide
#

lemme try it real quick

rough tide
#

This is the code I have. If it isn't clear, arrays and maps hurt my brain still

      // To kick list
      else if (subCommand === 'to_kick') {
        await interaction.deferReply({
          ephemeral: true,
        });
        const oneDay = 1000 * 60 * 60 * 24;
        const Guild = await interaction.guild;
        const Members = await Guild.members.cache;
        let msg = '';
        for (const memberMap of Members) {
          const member = memberMap[1];
          // console.log(member[1]);
          // if (await member)
          if (await member.roles.cache.has(DesignatedConsts.UnverifRole)) {
            const KickAt = member.joinedTimestamp + oneDay;
            if (await KickAt < Date.now() && !await member.roles.cache.has(DesignatedConsts.ExtendRole)) {
              msg = msg + `ID: ${member.user.id} ${member.user.tag}\n`;
              const row = new ActionRowBuilder()
              .addComponents(
                new SelectMenuBuilder()
                .setCustomId('userToKick')
                .setPlaceholder('No Users Selected.')
                .setMinValues(1)
                .addOptions(
                  memberMap.map(map => { return { label: memberMap.member.user.tag, description: memberMap.member.user.id };}),
                ),
              );
            }
          }
        }```
wispy void
#

that isn't really using maps, other than just checking the member role cache

#

Map (noun) class/structure
Array#map (verb) method

#

mapping on a djs Collection is additional behavior on top of the default Map, with behavior aligning with Array#map