#Creating system to add and delete users to a channel

99 messages · Page 1 of 1 (latest)

left sandBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
  • Marked as resolved by OP
proven tundra
#

const users = [];

        if (interaction.channel.members.permissionsIn(interaction.channel).has(PermissionFlagsBits.ViewChannel)) {
            // users.push(interaction.member)
            console.log(interaction.member)
        }

so something like this?

bright star
#

No why

#

interaction.channel.members is only the members with permission to view already

#

So all of that is redundant

tiny elbowBOT
proven tundra
kind needle
#

<channel>.members is a collection

proven tundra
#

yeh so in this example

interaction.channel.members is a collection with all the members that can see the channel

kind needle
#

Loop through it and add it

proven tundra
# kind needle Yes

So just loop throught interaction.channel.members add it to an array users and then add the values of the users array to a StringSelectMenuBuilder()?

delicate reef
#

Why are you back at using the <Channel>.members collection? As Said before none of this is needed for your use case. You are just making this overly complicated for no reason

proven tundra
kind needle
proven tundra
#

And if I don't know how else to do it, I can't do much but follow what others are saying

delicate reef
#

Then just <Channel>.members.map(member => ({your option for the SelectMenu}))

kind needle
proven tundra
#

so simple added the member as value

kind needle
#

You can add it to .addOptions() method

proven tundra
delicate reef
#

The other way around. <SelectMenuBuilder>.addOptions(interaction.channel.members.map(…))

kind needle
#

Umm no,

.addOptions(
Collection.map(m => ({
label: m.user.username,
value: m.id
}))
)
proven tundra
kind needle
#

Yes

delicate reef
#

Why interaction.members? You want to get all members that can view the channel, right? Not those that are selected in a UserSelectMenu

kind needle
#

Oh wait, yeah, <Channel>.members as Qjuh said

delicate reef
#

Please don’t confuse the members selected in an interaction with the members of a channel

proven tundra
#

But i got this problem

delicate reef
#

Also your code was still the wrong way around

kind needle
#

Also the code you sent is wrong on so many levels

#

Collection only refers to interaction.channel.members as it is a collection

delicate reef
#

interaction.channel.members is your Collection🐌

bright star
delicate reef
#

We‘re slowly reaching #rules 3 territory

proven tundra
kind needle
bright star
delicate reef
#

If you call that on a StringSelectMenuBuilder, yes

kind needle
proven tundra
bright star
tiny elbowBOT
proven tundra
#
            const row = new ActionRowBuilder().addComponents(
                new StringSelectMenuBuilder()
                    .setCustomId("userinhere")
                    .addOptions(
                        interaction.channel.members.map(m => ({
                            label: m.user.username,
                            value: m.id
                        }))
                    )
            )

it's must be builded like this right?

bright star
kind needle
#

Judging be their code, it doesn't looks like they use ts or they would be needed to use generics for builders

kind needle
proven tundra
bright star
kind needle
#

Yes

proven tundra
#

Alright everything is working with

            if (!interaction.member.permissions.has(PermissionFlagsBits.Administrator)) return interaction.reply({ content: "Je hebt hier geen permissies voor" });

            const removeUser = new ActionRowBuilder().addComponents(
                new StringSelectMenuBuilder()
                    .setCustomId("removinguser")
                    .addOptions(
                        interaction.channel.members.map(m => ({
                            label: m.user.username,
                            value: m.id
                        }))
                    )
            )

            await interaction.reply({
                content: `Kies welke gebruiker je wilt verwijderen van het kanaal`, components: [removeUser], ephemeral: true
            });
#

How can i fix that bots doesn't appear in the list of members

delicate reef
#

they don't appear and you want them to? or they do and you don't want that?

proven tundra
#

like this

delicate reef
#

then filter the collection by !member.user.bot

tiny elbowBOT
proven tundra
#

like first do .addOptions interachion.channel.members.map and then filter out the bots?

kind needle
proven tundra
kind needle
#

!member.user.bot*, otherwise yes

proven tundra
proven tundra
#

const row = new ActionRowBuilder().addComponents(
new UserSelectMenuBuilder()
.setCustomId("addinguser")
)

kind needle
#

I thought you were using String Select, where does User Select ckme from now?

proven tundra
kind needle
#

And like i said many times, user select is an auto populating menu, you can't choose to show only certain members, it'll show all

proven tundra
kind needle
proven tundra
kind needle
#

Well, you are adding only interaction.channel.members meaning members that can view that channel, so if those members exceed that, yes, it'll error

proven tundra
proven tundra
#

not on the adding part

#

for the adding part i needed all the users that are in the guild

kind needle
kind needle
proven tundra
kind needle
#

If the addingUserId is supposed to from UserSelectMenuInteraction, you don't need to use the id to fetch them, you can just <Interaction>.members.first() (assuming only one member can be selected at once) and that will give you the Member object

tiny elbowBOT
proven tundra
#

if (interaction.members.first().permissions.has(PermissionFlagsBits.Administrator)) return interaction.reply({ content: <@${removingUserID}> kan niet uit dit kanaal verwijderd worden, ephemeral: true }).then(() => {
setTimeout(() => {
interaction.deleteReply();
}, 5000);
})

why interaction.members.first doesn't work in the removinguser part

delicate reef
#

Why are you checking if the first member they want to remove is an admin?

proven tundra
delicate reef
#

But why only the first selected member? Or is it a single-select menu?

#

And what exactly doesn’t work about it?

proven tundra
#

TypeError: Cannot read properties of undefined (reading 'first')
at Object.execute (D:\DSModding\DSModding_DevelopmentBot\src\events\ticketButtonListener.js:131:37)
at Client.<anonymous> (D:\DSModding\DSModding_DevelopmentBot\src\functions\handelEvents.js:8:58)
at Client.emit (node:events:530:35)
at InteractionCreateAction.handle (D:\DSModding\DSModding_DevelopmentBot\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (D:\DSModding\DSModding_DevelopmentBot\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (D:\DSModding\DSModding_DevelopmentBot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (D:\DSModding\DSModding_DevelopmentBot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (D:\DSModding\DSModding_DevelopmentBot\node_modules@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.<anonymous> (D:\DSModding\DSModding_DevelopmentBot\node_modules@discordjs\ws\dist\index.js:1173:51)
at WebSocketShard.emit (D:\DSModding\DSModding_DevelopmentBot\node_modules@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:401:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)

Node.js v20.12.2
[nodemon] app crashed - waiting for file changes before starting...

delicate reef
#

interaction is not a UserSelectMenuInteraction then

#

Which makes sense seeing this is happening in a ButtonListener

proven tundra
#

and not for a stringselectmenubuilder?

delicate reef
#

Because a UserSelectMenu sends Users/GuildMembers on interaction. A StringSelectMenu sends strings. Not members

proven tundra
#

Alright