且构网

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

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

更新时间:2023-01-26 20:23:32

该文档说 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')