I am attempting to iterate over the output of discord.Server.roles
in order to output each role on the server I am connecting to.
The documentation states this for the declaration:
roles
A list of
Role
that the server has available.
However it seems that the resulting output is a class
called member_descriptor
which is non iterable.
See my example below:
import discord
import asyncio
client = discord.Client()
@client.event
async def on_ready():
print(type(discord.Server.roles))
try:
for i in discord.Server.roles:
print(i)
except:
print("Object is not iterable")
client.run(MY_SESSION_KEY)
Is anyone aware of whether it is possible to return a list of roles that a server has as this declaration is not returning a list but a class?
You need a realised server object, not just the class definition.
Basically, instead of using
discord.Server
, you should be usingclient.get_server("ID of server")