discord.py如何检查用户是否在服务器上?

时间:2020-05-25 13:33:19

标签: python discord discord.py

我需要检查用户是否在服务器上。请帮我 I mean function like this

2 个答案:

答案 0 :(得分:1)

您可以使用discord.Guild.get_member()按ID搜索行会,以按ID查找行会成员,如果找到,则返回discord.Member对象,如果找不到,则返回None

@bot.event
async def on_ready():
    guild = bot.get_guild(ID_OF_GUILD) # find ID by right clicking on server icon and choosing "copy id" at the bottom
    if guild.get_member(ID_OF_MEMBER) is not None: # find ID by right clicking on a user and choosing "copy id" at the bottom
        # the member is in the server, do something #
    else:
        # the member is not in the server, do something #

答案 1 :(得分:0)

首先,您需要通过名称或ID定义公会,然后获取已定义公会中的所有成员
这是您的代码:

Req.php