【问题标题】:How to get the age of someones account? Discord.py如何获取某人帐户的年龄?不和谐.py
【发布时间】:2020-05-05 18:52:48
【问题描述】:

为了防止新帐户使用某个命令,我如何在用户键入消息时获取用户帐户的年龄(或创建日期)。


client.get_user(account_date)

if account_date < 14:
   print('Your account must be older than 14 days to use this command')
else:
   print('Your account can use this command')

感谢任何帮助。

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    您可以从带有ctx.author 的ctx 或带有message.author 的消息中获取用户对象。

    然后在用户对象上你可以调用created_at

    例如获取当前用户的帐号

    @bot.command()
    async def CreatedAccountAt(self,ctx):
       await ctx.send(ctx.author.created_at)
    

    或通过 ID 获取用户创建日期

    @bot.command()
    async def CreatedAccountAt(ctx, userId: int):
        user =  bot.get_user(userId)
        await ctx.send(user.created_at)
    

    https://discordpy.readthedocs.io/en/latest/api.html#discord.User.created_at

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-11
      • 2021-08-04
      • 1970-01-01
      • 2019-05-09
      • 2019-02-04
      • 2021-08-01
      相关资源
      最近更新 更多