如何使用discord.py获取不和谐用户的用户ID [英] How do I get the User ID of a discord user using discord.py

查看:401
本文介绍了如何使用discord.py获取不和谐用户的用户ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Discord.py和Im尝试在用户键入频道时获取用户的Discord用户ID。

Im using Discord.py and Im trying to get the Discord userid of a user when they type into a channel.

当您进入开发人员模式时,可以找到该用户ID,然后右键单击一个用户名,将出现复制ID选项。

The userid can be found when you go into developer mode, and right click on a username, there will be an option "copy id".

当前api并未说明如何执行此操作,否则我会一直错过它

The current api is not saying how to do this, or I keep missing it

推荐答案

该文档说 User 类具有用户ID:

http://discordpy.readthedocs.io/en/latest/api.html#user

The documentation says that the User class have the user's id:
http://discordpy.readthedocs.io/en/latest/api.html#user

成员 User 的子类:

http://discordpy.readthedocs.io/en/latest/api.html#member

因此,如果您收到用户发来的消息,则可以使用 message.author.id 获取ID。 p>

So if you got a message from a user, you can get the id with message.author.id

import discord
import asyncio

client = discord.Client()

@client.event
async def on_ready():
    print('Logged in as')
    print(client.user.name)
    print(client.user.id)
    print('------')

@client.event
async def on_message(message):
    print(message.author.id)

client.run('token')

这篇关于如何使用discord.py获取不和谐用户的用户ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆