Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: interaction.member.roles.add is not a function #10523

Closed
MatteyGG opened this issue Sep 29, 2024 · 4 comments
Closed

TypeError: interaction.member.roles.add is not a function #10523

MatteyGG opened this issue Sep 29, 2024 · 4 comments

Comments

@MatteyGG
Copy link

MatteyGG commented Sep 29, 2024

Which package is this bug report for?

discord.js

Issue description

Cant add role to a member. I know, what something wrong with classes, but idk how to fix it(newbie).

I saw examples of implementation through cache, but I have no way to repeat it.

Mb helped:

ChatInputCommandInteraction {
  type: 2,
  id: 'xxxxxxxxxxxx',
  applicationId: 'xxxxxxxxxxxx',
  channelId: 'xxxxxxxxxxxx',
  guildId: 'xxxxxxxxxxxx',
  user: User {
    id: 'xxxxxxxxxxxx',
    bot: false,
    system: false,
    flags: UserFlagsBitField { bitfield: 0 },
    username: 'matteygg',
    globalName: 'MatteyGG',
    discriminator: '0',
    avatar: 'b145f403d753b86b83b54b1f01287d5b',
    banner: undefined,
    accentColor: undefined,
    avatarDecoration: null,
    avatarDecorationData: null
  },
  member: {
    user: {
      username: 'matteygg',
      public_flags: 0,
      id: 'xxxxxxxxxxxx',
      global_name: 'MatteyGG',
      discriminator: '0',
      clan: null,
      avatar_decoration_data: null,
      avatar: 'b145f403d753b86b83b54b1f01287d5b'
    },
    unusual_dm_activity_until: null,
    roles: [ '1289890391155413064', '1289888599357132830' ],
    premium_since: null,
    permissions: '2251799813685247',
    pending: false,
    nick: null,
    mute: false,
    joined_at: '2024-09-28T08:26:09.365000+00:00',
    flags: 0,
    deaf: false,
    communication_disabled_until: null,
    banner: null,
    avatar: null
  },
  version: 1,
  appPermissions: PermissionsBitField { bitfield: 562949953863680n },
  memberPermissions: PermissionsBitField { bitfield: 2251799813685247n },
  locale: 'ru',
  guildLocale: 'en-US',
  entitlements: Collection(0) [Map] {},
  commandId: '1289538567684755457',
  commandName: 'verification',
  commandType: 1,
  commandGuildId: 'xxxxxxxxxxxx',
  authorizingIntegrationOwners: { '0': 'xxxxxxxxxxxx' },
  context: 0,
  deferred: false,
  replied: false,
  ephemeral: null,
  webhook: InteractionWebhook { id: 'xxxxxxxxxxxx' },
  options: CommandInteractionOptionResolver {
    _group: null,
    _subcommand: null,
    _hoistedOptions: []
  }
}

Code sample

module.exports = {
  
  data: new SlashCommandBuilder()
    .setName("verification")
    .setDescription("Начать верификацию"),

async execute(interaction) {
//....
//....
//....
try {
      const verificationAproved = await response.awaitMessageComponent({
        filter: R45collectorFilter,
        time: 6000_000,
      });

      if (verificationAproved.customId === "accept") {
        NewUserInfo.setColor("Green");
        NewUserInfo.setFields({
          name: "Состояние",
          value: "Верификация пройдена",
          inline: true,
        });
        await interaction.member.roles.add("1289888599357132830"); //Cant add role
        await verificationAproved.update({
          content: "",
          embeds: [NewUserInfo],
          components: [],
        });
      } else if (verificationAproved.customId === "decline") {
        NewUserInfo.setColor("Red");
        NewUserInfo.setFields({
          name: "Состояние",
          value: "Верификация отклонена",
          inline: true,
        });

        await verificationAproved.update({
          content: "",
          embeds: [NewUserInfo],
          components: [],
        });
      }
    }
},
};

Versions

discord.js ^14.16.2
node v20.11.1

Issue priority

Low (slightly annoying)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

GuildMembers, GuildModeration

I have tested this issue on a development release

No response

@vladfrangu
Copy link
Member

Can you share the stacktrace of the error please?

@vladfrangu
Copy link
Member

Also, can you try this with the Guilds intent present too?

@MatteyGG
Copy link
Author

Yes, here it is, thanks for such a quick reply

TypeError: interaction.member.roles.add is not a function
at Object.execute (C:\Users..xxxxxxxxxxxx..\Code\NAME-discord-bot\commands\utility\verification.js:112:40)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.execute (C:\Users..xxxxxxxxxxxx..\Code\NAME-discord-bot\events\interactionCreate.js:16:4)

@MatteyGG
Copy link
Author

Sorry, it was my mistake, problem was in settings of my test bot in .dev discord portal.
image
Sorry again, your libary is super)

@Jiralite Jiralite closed this as not planned Won't fix, can't repro, duplicate, stale Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants