繁体   English   中英

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

[英]discord.py How to check if user is on server?

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

您可以使用discord.Guild.get_member()按 ID 按 ID 搜索成员的行会,如果找到,则返回discord.Member object,如果找不到,则返回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 #

首先,您需要通过名称或id定义一个公会,然后获取定义的公会上的所有成员
这是你的代码:

@bot.event
async def on_ready():
   guild = await bot.get_guild(ID) #fetch by ID
   guild = discord.utils.get(bot.guilds, name="Foo") # fetch by name
   for i in guild.members:
      print(i)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM