W
W
wetwixs2020-07-06 05:09:48
Python
wetwixs, 2020-07-06 05:09:48

How to infer people with a specific role?

Hello! Faced such a question, there is a command to display all participants on the server. I also need to display participants with a specific role. I tried to change it through the docks on discord.py, somehow in a shamanistic way - it didn’t work.
If you tell me I will be grateful to you.

The code itself and what comes out:

@client.command()
async def members_info(ctx):
    server_members = ctx.guild.members 
    data = "\n".join([i.name for i in server_members])
    embed = discord.Embed(title = f'Участники сервера', description = f"{data}", color = discord.Color.purple())
    
    await ctx.send(embed = embed)


A1jGObw.png

According to the idea, ideally, the bot should also display a list of participants, but only those who have a certain role.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
wetwixs, 2020-07-06
@wetwixs

Maybe I'm dumb and, I didn't specify something correctly, but now it just displays embed without a list.

@client.command()
async def members_info(ctx):
    server_members = ctx.guild.members 
    data = "\n".join([member.name for member in server_members if "Главный модератор" in member.roles])
    embed = discord.Embed(title = f'Участники сервера', description = f"{data}", color = discord.Color.purple())
    
    await ctx.send(embed = embed)

abrbxiV.png

N
nirbes, 2022-02-17
@nirbes

Maybe with a delay, while he was looking for a solution ... In general, here:

@client.command()
async def list(ctx, role: discord.Role):
    data = "\n".join([(member.name or member.nick) for member in role.members])
    embed=discord.Embed(title=f"Участники с ролью {role}\n", description=f"{data}\n")
    await ctx.send(embed=embed)

specify the command and role (you can either ping or by id)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question