简体   繁体   中英

Discord.js - Member Counter

So, what is up guys.

What im trying to do is pretty simple, but is still impossible for me. I want to put the Membercount of a specific guild in my bots activity and rename a channel to the member count.

What i currently got is this:

 let category = bot.channels.cache.find(channel => channel.id === '777307358187618319'); let guild = bot.guilds.cache.find(server => server.id === '777307357934780426'); bot.user.setActivity(auf ${guild.memberCount} User., {type:'WATCHING'}); category.setName(☔「 COMMUNITY 」- User: ${guild.memberCount}).catch(console.error); console.log(update successful ${guild.memberCount});

The code seems to be working fine, when im starting the bot and run the command the first time, everything works, but after the membercount changes and im trying to use the command again, it still sets it to the old count. Short: The bot saves the membercount on start, but doesnt really spit out the livecounter.

Might someone please help me out with this? Thank you!

Try this code. 100% will work with you.

 bot.on('ready', () => { setInterval(function() { // Important Variables let guild = bot.guilds.cache.get("GUILD_ID_HERE") let channel = bot.channels.cache.get("CHANNEL_ID_HERE") // Set Channel Name bot.setName(`☔ Members Count : ${guild.memberCount}`) // Set Bot Activity bot.user.setActivity(`☔ Guild Members : ${guild.memberCount}`, { type: "LISTENING" // client#Activity type }) }, 30000) // this line will change bot activity and channel name every 30 seconds })

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