NodeJS Discord.js查找回复消息的人是否具有特定角色

6ioyuze2  于 2023-04-20  发布在  Node.js
关注(0)|答案(1)|浏览(102)

当用户对消息作出React时,我需要知道他们是否具有几个接受的角色之一。接受的角色是:

const roles = ['Founder', 'The Board', 'Community Manager', 'Botmaster', 'Staff', 'Deputy Mods'];

然后,当一个用户对一条消息做出React时,我只想记录他们的角色中是否至少有一个与接受的角色中的至少一个匹配。现在我只想为一个特定的角色做这件事:

console.log(reaction.message.member.roles.cache.find(r => r.name === 'Bot Master'));

目前的问题是,无论谁做出React,它总是打印以下内容:

Role {
  guild: <ref *1> Guild {
    id: '686238814749851697',
    name: 'iTero Gaming',
    icon: 'a_c9d01a7737f0e70197a0ad54de54f018',
    features: [
      'AUTO_MODERATION',
      'GUILD_SERVER_GUIDE',
      'TEXT_IN_VOICE_ENABLED',
      'INVITE_SPLASH',
      'GUILD_ONBOARDING_HAS_PROMPTS',
      'WELCOME_SCREEN_ENABLED',
      'RAID_ALERTS_ENABLED',
      'COMMUNITY',
      'GUILD_ONBOARDING',
      'NEWS',
      'THREE_DAY_THREAD_ARCHIVE',
      'ANIMATED_ICON',
      'GUILD_ONBOARDING_EVER_ENABLED'
    ],
    commands: GuildApplicationCommandManager {
      permissions: [ApplicationCommandPermissionsManager],
      guild: [Circular *1]
    },
    members: GuildMemberManager { guild: [Circular *1] },
    channels: GuildChannelManager { guild: [Circular *1] },
    bans: GuildBanManager { guild: [Circular *1] },
    roles: RoleManager { guild: [Circular *1] },
    presences: PresenceManager {},
    voiceStates: VoiceStateManager { guild: [Circular *1] },
    stageInstances: StageInstanceManager { guild: [Circular *1] },
    invites: GuildInviteManager { guild: [Circular *1] },
    scheduledEvents: GuildScheduledEventManager { guild: [Circular *1] },
    autoModerationRules: AutoModerationRuleManager { guild: [Circular *1] },
    available: true,
    shardId: 0,
    splash: null,
    banner: null,
    description: null,
    verificationLevel: 1,
    vanityURLCode: null,
    nsfwLevel: 0,
    premiumSubscriptionCount: 3,
    discoverySplash: null,
    memberCount: 989,
    large: true,
    premiumProgressBarEnabled: true,
    applicationId: null,
    afkTimeout: 300,
    afkChannelId: null,
    systemChannelId: null,
    premiumTier: 1,
    widgetEnabled: null,
    widgetChannelId: null,
    explicitContentFilter: 2,
    mfaLevel: 1,
    joinedTimestamp: 1679960457532,
    defaultMessageNotifications: 1,
    systemChannelFlags: SystemChannelFlagsBitField { bitfield: 6 },
    maximumMembers: 250000,
    maximumPresences: null,
    maxVideoChannelUsers: 25,
    approximateMemberCount: null,
    approximatePresenceCount: null,
    vanityURLUses: null,
    rulesChannelId: '1026887740471660634',
    publicUpdatesChannelId: '1026885264758546442',
    preferredLocale: 'en-US',
    ownerId: '513795277841235983',
    emojis: GuildEmojiManager { guild: [Circular *1] },
    stickers: GuildStickerManager { guild: [Circular *1] }
  },
  icon: null,
  unicodeEmoji: null,
  id: '1070012259625074689',
  name: 'Bot Master',
  color: 3269542,
  hoist: true,
  rawPosition: 22,
  permissions: PermissionsBitField { bitfield: 1000831569473n },
  managed: false,
  mentionable: false,
  tags: {}
}

我认为如果.find方法没有找到角色,那么它根本不会打印,但它每次都在打印。
我做错了什么?

e5nqia27

e5nqia271#

console.log(reaction.message.member.roles.cache.find(r => r.name = 'Bot Master'));
在比较检索到的角色名称与字符串时,看起来您使用的是=而不是===。将=更改为===应该可以解决您的问题。

相关问题