[英]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.