繁体   English   中英

Discord.py Bot - 用户信息消息

[英]Discord.py Bot - User info message

我正在用 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 加入日期。 有任何想法吗?

提及discord Embed不能正常工作,请检查此stackoverflow 答案

要获取服务器加入日期不和谐加入日期,您可以分别在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')

输出: 在此处输入图片说明

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM