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

hey*_*rko -1 python discord discord.py

我需要检查用户是否在服务器上。请帮我 我的意思是这样的功能

Eri*_*Jin 6

您可以使用 来按 ID 搜索公会中的成员discord.Guild.get_member()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 #
Run Code Online (Sandbox Code Playgroud)