Reputation: 30
I'm trying to make a discord bot which will list all the admins of a server. It currently finds all roles with admin privileges and lists each member in them to the console. however, the bot only prints itself as an admin and doesn't show any of the other roles containing any members. I've got my code below:
async def get_admins(ctx):
admin_roles = [role for role in ctx.guild.roles if role.permissions.administrator]
admins = []
for role in admin_roles:
print(role)
print(role.members)
for member in role.members:
admins.append(member)
return admins
expected output:
Admin
[people, people, more people]
Bot
[itself]
actual output:
Admin
[]
Bot
[<Member id=844113179386707998 name='Orca' discriminator='1134' bot=True nick=None guild=<Guild id=807173965776027648 name='yea test medical bot' shard_id=None chunked=False member_count=5>>]
Any help would be greatly appreciated.
Upvotes: 0
Views: 269
Reputation: 201
Make sure to enable intents. I hope it works when you enable them. Go to your bot application on discord.dev and enable the intents. If you create a commands.Bot
instance, also add this:
intents = discord.Intents().all()
bot = commands.Bot(command_prefix="§",intents=intents)
If you enable intents, your bot can get all the members of a server.
Upvotes: 1