Discord bot只给我角色

时间:2020-11-03 02:47:09

标签: node.js discord discord.js bots

我正在努力使不和谐的机器人群体给我服务器中的每个人一个角色。每当我做-giveall时,只会给我这个角色。我试过使用地图和数组。使用message.guild.members.filter(member => member.roles.array().length > 1).forEach(member => member.addRole(role));时不走运。

if (command === 'giveall') {
    let role = message.guild.roles.cache.find(r => r.name == 'cool')

if (!role) return message.channel.send(`**${message.author.username}**, role not found`)
    message.guild.members.cache.filter(m => !m.user.bot).forEach(member => member.roles.add(role))
message.channel.send(`**${message.author.username}**, role **${role.name}** was added to all members`)
  }

1 个答案:

答案 0 :(得分:-1)

这是我通过console.log(message.guild.members.cache.filter(m => !m.user.bot));收到的日志:

Collection [Map] {
  '759457326251114536' => GuildMember {
    guild: Guild {
      members: [GuildMemberManager],
      channels: [GuildChannelManager],
      roles: [RoleManager],
      presences: [PresenceManager],
      voiceStates: [VoiceStateManager],
      deleted: false,
      available: true,
      id: '760015259619819550',
      shardID: 0,
      name: 'GoodGameBTW™',
      icon: '5c364ec985a0706a27c31b89953d01e4',
      splash: null,
      discoverySplash: null,
      region: 'india',
      memberCount: 10,
      large: false,
      features: [Array],
      applicationID: null,
      afkTimeout: 300,
      afkChannelID: null,
      systemChannelID: null,
      embedEnabled: undefined,
      premiumTier: 0,
      premiumSubscriptionCount: 0,
      verificationLevel: 'LOW',
      explicitContentFilter: 'ALL_MEMBERS',
      mfaLevel: 0,
      joinedTimestamp: 1603042420216,
      defaultMessageNotifications: 'MENTIONS',
      systemChannelFlags: [SystemChannelFlags],
      maximumMembers: 100000,
      vanityURLCode: null,
      vanityURLUses: null,
      description: null,
      banner: null,
      rulesChannelID: '771729349632196608',
      publicUpdatesChannelID: '768502471676788777',
      preferredLocale: 'en-US',
      ownerID: '759457326251114536',
      emojis: [GuildEmojiManager]
    },
    joinedTimestamp: 1601272158336,
    lastMessageID: '773102408938029056',
    lastMessageChannelID: '760778837612822558',
    premiumSinceTimestamp: 0,
    deleted: false,
    nickname: null,
    _roles: [ '760763514402111488', '760759896232296468' ],
    user: User {
      id: '759457326251114536',
      username: 'Prof. MineKraft',
      bot: false,
      discriminator: '6612',
      avatar: '97ee817e5098d3e6ee4c174a449d1779',
      flags: [UserFlags],
      lastMessageID: '773102408938029056',
      lastMessageChannelID: '760778837612822558'
    }
  }
}

从日志中,您可以看到缓存只有两个用户:机器人和您。因此,当您过滤掉漫游器时,只有您自己扮演角色。

这可能是因为您禁用了网关意图。请转到不和谐的开发人员门户并启用服务器成员意图。那应该可以解决您的问题。