I use this code to count discord members
class CONFING:
PREFIX = 'k.'
client = commands.Bot(command_prefix=CONFING.PREFIX)
client.remove_command('help')
@client.event
async def on_ready():
print('1')
print('2')
print('3')
print('GanGz Iz Here')
servers = len(client.guilds)
members = 0
for guild in client.guilds:
members += guild.member_count
await client.change_presence(activity = discord.Activity(
type = discord.ActivityType.watching,
name = f'✨{members} ᴍᴇᴍʙᴇʀꜱ'
))
and I wanna add active mics to activity too (I mean the users that they are connected to voice) I tried many ways but I failed
Advertisement
Answer
I add it a loop that refresh the status.
class CONFING:
PREFIX = 'k.'
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix=CONFING.PREFIX, intents=intents)
@client.event
async def on_ready():
print("n▄▀█ █░█░█ ░░█n█▀█ ▀▄▀▄▀ █▄█n")
if not loop.is_running():
loop.start()
@tasks.loop(seconds=10)
async def loop():
print("Refresh")
servers = len(client.guilds)
members = 0
connected_members = 0
for guild in client.guilds:
members += guild.member_count
for channel in guild.voice_channels:
connected_members += len(channel.members)
await client.change_presence(activity=discord.Game(f'✨{members} ᴍᴇᴍʙᴇʀꜱ⚡{connected_members} ᴍɪᴄ'))
print("Done")