Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何随机选择一个人discord.py_Python_Discord.py - Fatal编程技术网

Python 如何随机选择一个人discord.py

Python 如何随机选择一个人discord.py,python,discord.py,Python,Discord.py,我一直在尝试为我的discord bot发出一个命令,其中它会随机ping一个在线用户。根据这个答案,message.guild.memberson\u message(message)中的将为您提供服务器中所有成员的列表。只需从列表中随机选择一个条目 如果您想获得在线会员,可以检查用户状态 members = [m for m in guild.members if str(m.status) != "offline" or not m.bot] #this will re

我一直在尝试为我的discord bot发出一个命令,其中它会随机ping一个在线用户。

根据这个答案,
message.guild.members
on\u message(message)中的
将为您提供服务器中所有成员的列表。只需从列表中随机选择一个条目

如果您想获得在线会员,可以检查用户状态

members = [m for m in guild.members if str(m.status) != "offline" or not m.bot] #this will remove offline members and bots from members
target = random.choice(members)