A
A
Axel Encore2020-11-15 22:03:17
Python
Axel Encore, 2020-11-15 22:03:17

How to count the number of members and bots on a Discord server?

The counter of the number of users / bots on the server should be displayed and updated in the channel name. Discord.py
Example:
5fb17aff7bb23595965777.png

Thought to implement it like this:
but it doesn't work like that

@bot.event
async def on_member_join(member):
  guild = member.guild
  channel = get(guild.channels, name = 'test')
  await channel.edit(name = f'Учатники: {guild.member_count}')

@bot.event
async def on_member_remove(member):
  guild = member.guild
  channel = get(guild.channels, name = 'test')
  await channel.edit(name = f'Учатники: {guild.member_count}')

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Nevzorov, 2020-11-17
@axelencore

Your code will only work once. In the next triggers, the channel name will no longer be "test". Get the channel by ID, instead of the name, for example, through guild.get_channel(ID)
Remember that members intent is required: on_member_joinhttps ://discordpy.readthedocs.io/en/stable/api.htm... Also remember that there is limit to 2 channel changes in 10 minutes:on_member_remove
7Nmbvar.png
7R6fTEb.png

N
Nikita Kudrin, 2020-11-15
@HepkaPlay

Let's start with the fact that you need to search for a channel by its ID or the beginning of the name.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question