简体   繁体   English

discord.js 语音通道成员数

[英]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.如果我对您的理解正确,您想将 VC 重命名为成员数。 The Discord API only lets you rename a channel 2 times every 10 minutes. Discord API 仅允许您每 10 分钟重命名通道 2 次。 You are trying to run that code every 5 seconds.您正尝试每 5 秒运行一次该代码。

Try setting your timeout delay to 600000 instead of 5000 .尝试将超时延迟设置为600000而不是5000

You could try to use voiceStateUpdate , it's fired everytime a user leaves, enters, mutes mic or unmutes mic.您可以尝试使用voiceStateUpdate ,每次用户离开、进入、静音或取消静音时都会触发它。 Here's a link to it: voiceStatusUpdate这是它的链接: voiceStatusUpdate

You can also use voiceChannelID if you want to get the ID of the channel.如果要获取频道的 ID,也可以使用voiceChannelID Here a link: voiceChannelID这里有一个链接: 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

  }
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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