简体   繁体   中英

discord.js voice channel member count

I have the problem that the bot the member count updates only once and does nothing else after. Does anyone know how to solve it? 在这里,您在右侧看到公共柜台机器人的图片,左侧是我的机器人与频道

Heres my current code:

bot.on("ready", () => {
    const guild = bot.guilds.cache.get('779790603131158559');
    setInterval(() => {
        const memberCount = guild.memberCount;
        const channel = guild.channels.cache.get('802083835092795442')
        channel.setName(`DC︱Member: ${memberCount.toLocaleString()}`)
    }, 5000);
});

If I am understanding you correctly, you want to rename a VC to the member count. The Discord API only lets you rename a channel 2 times every 10 minutes. You are trying to run that code every 5 seconds.

Try setting your timeout delay to 600000 instead of 5000 .

You could try to use voiceStateUpdate , it's fired everytime a user leaves, enters, mutes mic or unmutes mic. Here's a link to it: voiceStatusUpdate

You can also use voiceChannelID if you want to get the ID of the channel. Here a link: voiceChannelID

Here's a basic idea of the code you can use:

bot.on('voiceStateUpdate', (oldMember, newMember) => {
  let newUserChannel = newMember.voiceChannel
  let oldUserChannel = oldMember.voiceChannel


  if(oldUserChannel === undefined && newUserChannel !== undefined) {

     // User Joins a voice channel

  } else if(newUserChannel === undefined){

    // User leaves a voice channel

  }
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM