Answer the question
In order to leave comments, you need to log in
Why does the function to edit the channel under online in discord.py not work?
The function to edit the channel does not work, in which it should be online:
@client.event
async def update_online():
online_now = sum([0 if member.status == discord.status.offline else 1 for member in after.guild.members])
channel = bot.get_channel(806502570696376390)
await channel.edit(name=f"ONLINE: {online_now}")
Answer the question
In order to leave comments, you need to log in
https://discordpy.readthedocs.io/en/stable/api.htm...
on_
on_update_online()
doesn't exist, you need it on_member_update(before, after)
: https://discordpy.readthedocs.io/en/stable/api.htm...from datetime import datetime
...
last_time = datetime.now()
@client.event
async def on_member_update(before, after):
if (datetime.now() - last_time).total_seconds() > 60*5: # один раз в пять минут
return
last_time = datetime.now()
online = len([m for m in after.guild.members if m.status != discord.Status.offline])
await bot.get_channel(CHANNEL_ID).edit(name=f"Online: {online}")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question