本文介紹了Discord.js 帳戶創(chuàng)建后的天數(shù)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
如果用戶注冊(cè)discord不到10天,有什么方法可以在用戶加入服務(wù)器時(shí)賦予他們特定的角色.
Is there any way to give a user a certain role when they join the server, if they have been registered to discord for less than 10 days.
推薦答案
使用 User 的 .createdAt
屬性來(lái)確定他們的帳戶年齡
Use the .createdAt
property of User to determine their account age
當(dāng) guildMemberAdd
事件觸發(fā)時(shí),檢查加入成員的 .createdAt
屬性.然后你可以使用 .addRole()
給他們一個(gè)角色.
When the guildMemberAdd
event triggers, check the joining member's .createdAt
property. You can then use .addRole()
to give them a role.
// assuming you already have the `role` object or id
client.on("guildMemberAdd", member => {
if (Date.now() - member.user.createdAt < 1000*60*60*24*10) {
member.addRole(role);
}
});
更詳細(xì)的解釋:
guildMemberAdd
將在每次有人加入服務(wù)器時(shí)觸發(fā),這將傳遞member
對(duì)象.- 我們使用該成員的
user
對(duì)象來(lái)確定帳戶是何時(shí)通過(guò).createdAt
創(chuàng)建的. - 時(shí)間戳以毫秒為單位存儲(chǔ),因此 10 天相當(dāng)于
1000*60*60*24*10
毫秒. - 比較這兩個(gè)時(shí)間戳,如果他們的帳戶年齡較低,那么你就給他們一個(gè)角色.
- 我們假設(shè)您已經(jīng)擁有
role
對(duì)象.否則,Guild.roles.get()
是通過(guò) ID 查找角色的好方法.
guildMemberAdd
will fire every time someone joins a server, this will pass on themember
object.- We use the
user
object from that member to determine when the account was created via.createdAt
. - Timestamps are stored in milliseconds, so 10 days is equivalent to
1000*60*60*24*10
milliseconds. - Compare these two timestamps, and if their account age is lower, then you give them a role.
- We're assuming you already have the
role
object. OtherwiseGuild.roles.get()
is a good way to find a role by its ID.
這篇關(guān)于Discord.js 帳戶創(chuàng)建后的天數(shù)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!