Python 3.x 如何获取成员的服务器详细信息
如何使用用户ID获取成员的详细信息。例如,我想知道在添加我的bot之前,他是哪个服务器(名称和ID)的成员。这很简单,只要遍历bot可以访问的所有服务器并尝试从每个服务器检索该ID的Python 3.x 如何获取成员的服务器详细信息,python-3.x,discord.py,Python 3.x,Discord.py,如何使用用户ID获取成员的详细信息。例如,我想知道在添加我的bot之前,他是哪个服务器(名称和ID)的成员。这很简单,只要遍历bot可以访问的所有服务器并尝试从每个服务器检索该ID的成员对象即可 from discord.ext import commands bot = commands.Bot(command_prefix='!') @bot.command(pass_context=True) async def getUser(ctx, id): # id = int(id)
成员对象即可
from discord.ext import commands
bot = commands.Bot(command_prefix='!')
@bot.command(pass_context=True)
async def getUser(ctx, id):
# id = int(id) # On the rewrite branch, ids are ints
for server in bot.servers:
member = server.get_member(id)
if member:
await bot.say(f"Server Name: {server.name}")
await bot.say(f"Server ID: {server.id}")
bot.run("TOKEN")