具有特定角色的语音通道统计机器人

时间:2020-06-23 17:58:15

标签: javascript node.js discord discord.js

嘿,我尝试创建一个“语音通道统计信息机器人”,但遇到一个问题,我无法按某些组过滤器进行过滤,因此当有人进入和离开服务器时,仅计算勇敢的角色。

GuildMemberAddEvent

const BaseEvent = require('../utils/structures/BaseEvent');
module.exports = class GuildMemberAddEvent extends BaseEvent {
  constructor() {
    super('guildMemberAdd');
  }
  
  async run(client, member) {
  if (member.guild.id !== config.serverid) return;
  
  client.channels.cache.get(config.wolvesc).setName(`? Wölfe: ${member.guild.roles.cache.get("718011794723176491").members.size}`);
  client.channels.cache.get(config.teamc).setName(`? Team: ${member.guild.roles.cache.get("721922261560590408").members.size}`);
  client.channels.cache.get(config.boosterc).setName(`? Boosters: ${member.guild.roles.cache.get("718231071442862121").members.size}`);
  }
}

GuildMemberRemoveEvent

const BaseEvent = require('../utils/structures/BaseEvent');
module.exports = class GuildMemberRemoveEvent extends BaseEvent {
  constructor() {
    super('guildMemberRemove');
  }
  
  async run(client, member) {
  if (member.guild.id !== config.serverid) return;
  
  client.channels.cache.get(config.wolvesc).setName(`? Wölfe: ${member.guild.roles.cache.get("718011794723176491").members.size}`);
  client.channels.cache.get(config.teamc).setName(`? Team: ${member.guild.roles.cache.get("721922261560590408").members.size}`);
  client.channels.cache.get(config.boosterc).setName(`? Boosters: ${member.guild.roles.cache.get("718231071442862121").members.size}`);
  }
}

感谢任何可以帮助我的人。

1 个答案:

答案 0 :(得分:0)

我又一个人发现了它,所以在这里问是很愚蠢的,但是对于所有需要更新版本的人来说,我将在这篇文章下编写它,并进行有趣的编程。

ready.js

    const guild = client.guilds.cache.get(process.env.DISCORD_SERVER_ID);

    const wolvesCount = client.channels.cache.get(process.env.DISCORD_CHANNEL_WOLVES);
    const teamCount = client.channels.cache.get(process.env.DISCORD_CHANNEL_TEAM);
    const boosterCount = client.channels.cache.get(process.env.DISCORD_CHANNEL_BOOSTER);

    setInterval(function() {

    var wolvesRole = guild.roles.cache.get(process.env.DISCORD_ROLE_WOLVES).members.size;
    var teamRole = guild.roles.cache.get(process.env.DISCORD_ROLE_TEAM).members.size;
    var boosterRole = guild.roles.cache.get(process.env.DISCORD_ROLE_BOOSTER).members.size;

    wolvesCount.setName("? Wölfe: " + wolvesRole)
    .catch(console.error);

    teamCount.setName("? Team: " + teamRole)
    .catch(console.error);

    boosterCount.setName("? Booster: " + boosterRole)
    .catch(console.error);
    }, 30000)