Answer the question
In order to leave comments, you need to log in
How to display number of users online in discord voice channel name,.js?
Hey! I need a function (or something similar) so that I can display those who are online on my discord server through the name of the voice channel. How could this be implemented? (If possible, it would not be bad to display all participants, not including bots and separately participants in the network)
Answer the question
In order to leave comments, you need to log in
You can do it this way, I tested it, it seems to work, it doesn’t capture bots
(attention, I wrote the checks in haste and I’m almost a beginner myself)
function СhCounter( guild, ChCounter, UpdateTime = 10000 ) {
// guild - Объект гильдии, ChCounter - Объект канала в этой гильдии, UpdateTime - обновлять каждые N ms
if ( !guild || !ChCounter || UpdateTime < 1000 ) return 0; // Проверка на валидность
const Users = guild.members.cache.filter(m => m.user.bot === false) //Все юзеры
const OnlineCount = Users.filter(m => m.presence.status != 'offline').size //Число юзеров онлайн
ChCounter.setName(`${OnlineCount} / ${Users.size} online members`); // Меняем название канала
setTimeout( СhCounter, UpdateTime, guild, ChCounter, UpdateTime ); // Вызываем повторно через UpdateTime ms
}
//Токен уже введёт, логин произведён
const couterConfig = {
guildID: "YOU GUILD ID",
chID: "YOU CHANNEL ID"
}
client.on("ready", () => {
test_GUILD = client.guilds.cache.get(couterConfig.guildID);
if (!test_GUILD ) return console.log("Не могу найти гильдию для подсчёта") // Проверочка валидности
test_Channel = test_GUILD.channels.cache.get(couterConfig.chID);
if (!test_GUILD ) return console.log("Не могу найти канал для подсчёта") // Проверочка валидности
console.log("Начинаю считать");
СhCounter(test_GUILD, test_Channel, 5000); // Вызов ф-и
}
QQ!
Tomorrow I will sit down at the PC and I can make a code if there is no answer, but for now I will explain for the rest:
It means to display the number of users in voice channels.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question