Answer the question
In order to leave comments, you need to log in
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)
Answer the question
In order to leave comments, you need to log in
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)
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)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question