I'm trying to write a code for a discord bot (python) that will show a list of members belonging to a specific role.
Sorry for the long question, I'm new to coding and trying to be as thorough as possible, as I'm learning by doing.
@client.command()
async def team(ctx): # Always same role, no input needed
guild = ctx.message.guild
tk = guild.get_role(role_id)
tkm = tk.members
# print(type(tkm)) shows it as "list"
for row in tkm:
a = row.name
# print(type(a)) # shows "<class 'discord.member.Member'>" x amount of times
await ctx.send(a)
This does sort of work. The bot sends the name of each member in that role in separate messages, but it's very slow and even "stops" every time after listing 4-5 members. I have searched around, and only found similar codes.
The reason I'm not doing ctx.send(tkm) is because it contains too much info, for every member. This it can post in the chat in one go.
[<Member id=_________ name='___' discriminator='__' bot=False nick='_____' guild=<Guild i
_______ name='________' shard_id=None chunked=True member_count=28>>,....]
It will not let me do tkm.name (It's a list, and lists don't have attribute 'name') I'm only interested in name, hence the "a = row.name" which does give me just the names of the members. but also results in the list splitting up and giving me these objects
<class 'discord.member.Member'>
<class 'discord.member.Member'>
...
...
Where I'm stuck is: I can't seem to do tkm = tk.members.name (again, because of no attribute 'name')
What I want from here, is to get the members from "a" back in to a list, and then post the new list in the chat. But I can't seem to figure out how. Or if there is a way of manipulating "tkm" to only have member names to begin with that will also works.
Thank you :)