且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 discord.py 获取不和谐用户的用户 ID

更新时间:2023-01-26 20:19:08

文档说 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

MemberUser 的子类:
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')