How do I get the User ID of a discord user using discord.py

偶尔善良 提交于 2019-12-07 20:31:34

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

And that Member is a subclass of User:
http://discordpy.readthedocs.io/en/latest/api.html#member

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')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!