Kuezy
Kuezy

Reputation: 101

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?Here you see a picture of a public counter bot on the right and on the left is my bot with the channel

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);
});

Upvotes: 1

Views: 4822

Answers (2)

InsertDisplayNameHere
InsertDisplayNameHere

Reputation: 122

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.

Upvotes: 1

alapaah
alapaah

Reputation: 353

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

  }
})

Upvotes: 0

Related Questions