本文介紹了如何獲取某人帳戶的年齡?不和諧.py的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
為了防止新帳戶使用某個命令,我如何在用戶鍵入消息時獲取用戶帳戶的年齡(或創建日期).
To prevent new accounts from using a certain command, how could I get the age of a users account (or creation date) when they type a message.
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')
感謝任何幫助.
推薦答案
您可以使用 ctx.author
從 ctx 或使用 message.author的消息中獲取 User 對象代碼>.
You can get a User object from either ctx with ctx.author
or from a message with message.author
.
然后在 User 對象上你可以調用 created_at
.
Then on the User object you can call created_at
.
例如獲取當前用戶的帳號
So for example to get account of current user
@bot.command()
async def CreatedAccountAt(self,ctx):
await ctx.send(ctx.author.created_at)
或通過 ID 獲取用戶創建日期
or to get a user created date by 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
這篇關于如何獲取某人帳戶的年齡?不和諧.py的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!