How do I get the User ID of a discord user using discord.py(如何使用 discord.py 获取不和谐用户的用户 ID)
问题描述
我正在使用 Discord.py,并且我试图在用户输入频道时获取用户的 Discord 用户 ID.
Im using Discord.py and Im trying to get the Discord userid of a user when they type into a channel.
进入开发者模式可以找到userid,在用户名上右击,会有一个选项copy 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
而 Member
是 User
的子类:
http://discordpy.readthedocs.io/en/latest/api.html#member
因此,如果您收到来自用户的消息,则可以使用 message.author.id
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 discord.py 获取不和谐用户的用户 ID
基础教程推荐
- 筛选NumPy数组 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01