简体   繁体   English

discord.py 会员在 discord 注册并加入服务器时如何获取信息

[英]discord.py how to get info when member registered on discord, and joined server

i want to create command to see when that person who write command registered on discord and when he joined my server, i tryed author.joined_at and author.created_at but this doesn't work tried to find on API reference too, but no results我想创建命令以查看编写命令的人何时在 discord 上注册并且当他加入我的服务器时,我尝试了author.joined_atauthor.created_at但这不起作用试图在 API 参考上找到,但没有结果

when i use this code bot just not replying, i don't know the problem, when i replace funcions everything work, so i think(maybe i am wrong) that problem in incorrect using of functions or me of them, that's why i asked当我使用这个代码机器人只是不回复时,我不知道问题所在,当我替换函数时一切正常,所以我认为(也许我错了)错误使用函数或我的问题,这就是我问


@client.command( aliases = ['uinfo'])

async def userinfo( ctx ):
    emb = discord.Embed( title = f'{ ctx.author } | { ctx.author.display_name }', color = discord.Color.green(), description = f'{ctx.author.id} |' )
    emb.set_thumbnail( url = ctx.author.avatar_url )
    emb.add_field( name = 'Joined server', value = f'{ author.joined_at }' )
    emb.add_field( name = 'Joined discord', value = f'{author.created_at}' )

    await ctx.send( embed = emb )

For the date the user joined the server, I use this code:对于用户加入服务器的日期,我使用以下代码:

ctx.author.joined_at.strftime(date_format)

And for the date of the user's registration, I use this:对于用户注册的日期,我使用这个:

ctx.author.created_at.strftime(date_format)

This is explained here .这是解释here

"Date format" is a variable I created so that the date and time will be easy to understand, for example, this is mine: “日期格式”是我创建的一个变量,以便日期和时间易于理解,例如,这是我的:

date_format = "%a, %b %d, %Y @ %I:%M %p" 

I hope you find this useful!希望这个对你有帮助!

    async def whois(self, ctx, *, user: discord.Member = None):
         if user is None:
             user = ctx.author      
         date_format = "%a, %d %b %Y %I:%M %p"
         embed = discord.Embed(color=0xFF0000, description=user.mention)
         embed.set_author(name=str(user), icon_url=user.avatar_url)
         embed.set_thumbnail(url=user.avatar_url)
         embed.add_field(name="Joined Server", value=user.joined_at.strftime(date_format), inline=False)
         members = sorted(ctx.guild.members, key=lambda m: m.joined_at)
         embed.add_field(name="Join Position", value=str(members.index(user)+1), inline=False)
         embed.add_field(name="Joined Discord", value=user.created_at.strftime(date_format), inline=False)
         if len(user.roles) > 1:
             role_string = ' '.join([r.mention for r in user.roles][1:])
             embed.add_field(name="Roles [{}]".format(len(user.roles)-1), value=role_string, inline=False)
         embed.set_footer(text='ID: ' + str(user.id))
         return await ctx.send(embed=embed)

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

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