0

Code:

import random
user = random.choice(message.guild.members)
await message.channel.send('Hello ' + user.mention)

My question is how do I ping a random, non-bot user in Discord.py?

Any help on this will be greatly appreciated, thanks!

2 Answers 2

2

You can check if a user is a bot with Member.bot which returns a bool

Use a list comprehension to sort the members in the guild that are not bots(user accounts) and then use random.choice accordingly.

import random

humans = [m for m in message.guild.members if not m.bot]
random_member = random.choice(humans)

await message.channel.send(f"Hello {random_member.mention}")
0
0

Try an if statement to see if the user is a bot.

if not user.bot:
    await message.channel.send('Hello ' + user.mention)

You can get more information here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.