EchoTheAlpha
EchoTheAlpha

Reputation: 422

Saving an array of all server members using Discord.py-Rewrite

Is there a way I can return an array of all the members of a server? I'm trying to make a "Who would" command where someone does "!whowould do something" And then it randomly picks a user from the server and says "USER would do something" I tried this.

@bot.command()
async def whowould(ctx, *args):
    print(ctx.guild.members)

I tried that to just see what it did, but it gathered more information than just the usernames and tags of the user.

I want to be able to save the members of a server as an array so i can use the random module.

Upvotes: 1

Views: 1095

Answers (1)

Patrick Haugh
Patrick Haugh

Reputation: 61042

Guild.members is already a list of Member objects. You should use random.choice to select one, then use Member.display_name or Member.mention to get thir name or mention them:

@bot.command()
asyc def ping_random(ctx):
    member = random.choice(ctx.guild.members)
    await ctx.send(f"{member.mention}")

Upvotes: 3

Related Questions