【问题标题】:How do I get the User ID of a discord user using discord.py如何使用 discord.py 获取不和谐用户的用户 ID
【发布时间】:2017-09-18 11:51:58
【问题描述】:

我正在使用 Discord.py,并且试图在用户输入频道时获取用户的 Discord 用户 ID。

进入开发者模式可以找到userid,在用户名上右击,会有一个“copy id”选项。

当前的 api 没有说明如何做到这一点,或者我一直错过它

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    文档说User 类有用户ID:
    http://discordpy.readthedocs.io/en/latest/api.html#user

    MemberUser 的子类:
    http://discordpy.readthedocs.io/en/latest/api.html#member

    因此,如果您收到来自用户的消息,则可以使用message.author.id 获取 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 的 OAuth2 的问题。我试图使用 oauth2 获取用户 ID,但它没有返回它。我正在使用这个插件github.com/teamreflex/oauth2-discord
    • @GibsLeFleur 这不是我所知道的,我建议您创建另一个关于此的问题
    • 有没有一种方法可以从 @username 中获取 id 并传递给命令函数?
    猜你喜欢
    • 1970-01-01
    • 2019-05-09
    • 2019-05-31
    • 1970-01-01
    • 2020-10-09
    • 2021-05-07
    • 2021-08-04
    • 2021-07-18
    • 2019-04-01
    相关资源
    最近更新 更多