【问题标题】:Discord.py Bot - User info messageDiscord.py Bot - 用户信息消息
【发布时间】:2021-12-04 19:25:30
【问题描述】:

我正在用 Python 制作一个 Discord 机器人,目前,我想添加一个功能,当使用 _userinfo 命令时,机器人将发送有关用户的一般信息(他加入 Discord 的日期,他加入此服务器的日期,他的昵称和头像)

我目前有这个代码:

if message.content.startswith("_userinfo"):
    emb14 = discord.Embed(
        title=f"{message.author.mention} info",
        colour=discord.Colour.dark_blue()
    )
    emb14.set_image(url=message.author.avatar_url)
    emb14.add_field(name=f"{message.author.mention}", value=f"{message.author}", inline=True)
    await message.channel.send(embed=emb14)

但后来我收到了这条消息:

问题是昵称是 ID(但不是nickname#0000),而且我不知道如何添加服务器加入日期和 Discord 加入日期。有什么想法吗?

【问题讨论】:

    标签: python discord bots


    【解决方案1】:

    提及不适用于discord Embed,请检查此stackoverflow answer

    要获取服务器加入日期不和谐加入日期,您可以分别在user 上使用created_atjoined_at 属性。

    请看下面这段代码,

    import discord
    
    client = discord.Client()
    
    @client.event
    async def on_ready():
        print(f'Logged in as {client.user}')
    
    @client.event
    async def on_message(message):
        if message.content.startswith("_userinfo"):
            emb14 = discord.Embed(
                title=f"@{message.author} info:",
                colour=discord.Colour.dark_blue()
            )
            emb14.set_image(url=message.author.avatar_url)
            emb14.add_field(name=f"Name", value=f"{message.author}", inline=True)
            emb14.add_field(name=f"Discord Joined date", value=f"{message.author.created_at}", inline=True)
            emb14.add_field(name=f"Server Joined date", value=f"{message.author.joined_at}", inline=True)
            await message.channel.send(embed=emb14)
    
    client.run('YOUR TOKEN')
    

    输出:

    【讨论】:

    • 非常感谢!帮了大忙!
    【解决方案2】:

    尝试将{message.author.mention} 更改为<@{message.author.id}>。另外,请注意在标题和页脚中提及不起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-11
      • 1970-01-01
      • 2021-09-10
      • 2021-03-27
      • 2021-10-04
      • 2018-07-24
      • 2021-08-23
      • 2019-02-20
      相关资源
      最近更新 更多