#Bot is able to add the user to a channel, but not another user in the server

68 messages · Page 1 of 1 (latest)

open dagger
#

Hi!

Inside of a slash command, I display the user a list of other users available to help him.
This is done with a selectMenu.

As soon as the users selects a value, a new channel is created with himself, and the selected person.

However, it only works for himself. The selected person returns an error Supplied parameter is not a User nor a Role. unless the user adds himself, which in this case, it works perfectly!

Am I missing a permission or something else?

Code:

const createChannel = (message, selected) => {
  console.log(message.interaction.user.id); // 197011180198297610
  console.log(selected); // 111204161931972608
  message.guild.channels.create({
    name: "test",
    parent: "1039479842506297354",
    permissionOverwrites: [
      {
        type: "member",
        id: selected,
        allow: [PermissionFlagsBits.ViewChannel],
      },
      {
        type: "member",
        id: message.interaction.user.id,
        allow: [PermissionFlagsBits.ViewChannel],
      },
      {
        type: "role",
        id: "1039143797352837130",
        deny: [PermissionFlagsBits.ViewChannel],
      },
    ],
  });
};
winter patio
#

• 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.

open dagger
#

node: 16.17.0
discord.js: 14.6.0

Full error stack:

Ready!
111204161931972608
197011180198297610
/home/guillaume/dev/sws/discord/node_modules/discord.js/src/structures/PermissionOverwrites.js:184
    if (!userOrRole) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'parameter', 'User nor a Role');
                           ^

TypeError [InvalidType]: Supplied parameter is not a User nor a Role.
    at Function.resolve (/home/guillaume/dev/sws/discord/node_modules/discord.js/src/structures/PermissionOverwrites.js:184:28)
    at /home/guillaume/dev/sws/discord/node_modules/discord.js/src/managers/GuildChannelManager.js:149:81
    at Array.map (<anonymous>)
    at GuildChannelManager.create (/home/guillaume/dev/sws/discord/node_modules/discord.js/src/managers/GuildChannelManager.js:149:51)
    at createChannel (/home/guillaume/dev/sws/discord/commands/search.js:122:26)
    at /home/guillaume/dev/sws/discord/commands/search.js:109:9
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'InvalidType'
}
#

To isolate the issue, I tried removing the variable selected and replacing it by a string.

If this strings === the user doing the interaction it works
if the string !== the user doing the interaction, I have the error above

lethal grove
#

@open dagger are you using a string select menu?

#

if yes, then the only reason i could think of after following d.js source code is that the target is uncached.
since the id is resolved via DataManager, and if it's a string then return this.cache.get(idOrInstance) ?? null;

#

this checks out since discord always sends member that used the interaction, so they will be in the cache

open dagger
#

Yes it is a string select menu, the values are discord IDS stored in my database

lethal grove
#

well, then the member with the id is not cached

open dagger
#

I see, didn't know about the cache

#

How can I fix it tho?

lethal grove
#

well, it's not really clear and in this instance it shouldn't need to do that

#

and we're trying to add alternative ways to do certain things without the need to have certain things cached

#

anyway, the easiest fix would be to just call await interaction.guild.members.fetch(selected)

open dagger
#

to be sure to understand, this will add the user to the cache?

lethal grove
#

yes, fetching caches (unless you disable that, obviously)

#

so you don't even need to store the result of that

open dagger
#

I see, will try right away

#

Hopefully I didn't disable anything, let's find out ^^

lethal grove
#

no, as in option passed to fetch()

open dagger
#

Ah yeah makes sense

#

doesn't seem to work, I still have the same error, and if I log the result of fetch() I have null as nickname

lethal grove
#

well, nickname isn't username

open dagger
#

what in the response will tell me that it worked ?

lethal grove
#

if you await it, it should just work

open dagger
#

I'm wondering because the docs doesn't seem to take an ID as fetch param

#

Maybe I'm looking at the wrong place tho

lethal grove
#

that's not correct thing

open dagger
#

ah my bad then

lethal grove
#

you're not doing member.fetch()

open dagger
#

Well I do have a response so we can assume it worked

#

But I still have the error I had before

#

Maybe I can log the cache and see what's in there 🤔

lethal grove
#

show code first

lethal grove
#

sigh

astral gazelle
#

did I miss something dogeHaHa

open dagger
#

I didn't understand your message sorry :/

#

Cleaning up the code a bit ^^

lethal grove
#

in v14 everything is an enum

#

so it's not type: 'member'

open dagger
#

everything works now!

#

Thanks a lot

lethal grove
#

but unless i have a stroke and can't read js, it should work without that

astral gazelle
lethal grove
#

🤔

open dagger
#

Yeah I don't think that it fixed it, it was the caching

open dagger
#

When I last said it still doesn't work, I had one line still hardcoded I forgot to put back as selected var

lethal grove
#

ah

#

yeah

open dagger
#

So the caching worked, and it fixed the issue 🙂

lethal grove
#

if you use OverwriteType.Member, then it doesn't use cache

open dagger
#

Ooooh

lethal grove
#

if you don't, then it tries to resolve from cache

open dagger
#

let me try to remove it

lethal grove
#

since it doesn't know if it's a role or a member id

#

(and it doesn't accept strings as type anymore)

open dagger
#

Yes indeed now with the enum type, I could remove await interaction.guild.members.fetch(selected) and it still works

#

Much cleaner i like it

lethal grove
#

yeah, that was kinda the thing i was looking at that wouldn't need cache

#

since i was surprised it looked like it did

open dagger
#

I must have stolen it from some outdated stackoverflow 😅

astral gazelle
open dagger
#

Thanks a lot to the both of you!! Would have taken so much time to figure that one out x)