Discord PY获取服务器的所有成员 [英] Discord PY getting all members of a server

查看:59
本文介绍了Discord PY获取服务器的所有成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

discord.py还很陌生,并且希望获取使用该机器人的Discord服务器中所有人员的ID.

Im pretty new to discord.py and would like to get the ids of all the people in the discord server that the bot is used in.

谢谢,阿拉夫

推荐答案

首次使用应在命令中从 ctx.guild 中获取 guild 对象事件, on_message 事件中的 message.guild 等.然后选择以下示例.

First use should get guild object from ctx.guild in command event, message.guild in on_message event, etc. Then choose the sample below.


示例要遍历所有成员并做一些事情

The sample to go through all members and do some stuff

for member in guild.members:
    id = member.id

    # Do stuff here


获取所有会员ID列表的示例

The sample to get a list of all members ids

ids = [member.id for member in guild.members]


获取所有会员id的样本的样本

The sample to get an itterator of all members ids

def get_all_members_ids(guild):
    for member in guild.members:
        yield member.id

# And then use it like this
for id in get_all_members_ids(guild):
    # Do stuff here

这篇关于Discord PY获取服务器的所有成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆