如果用户注册discord不到10天,有什么方法可以在用户加入服务器时赋予他们特定的角色.
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
属性来确定他们的帐户年龄
Use the .createdAt
property of User to determine their account age
当 guildMemberAdd
事件触发时,检查加入成员的 .createdAt
属性.然后你可以使用 .addRole()
给他们一个角色.
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);
}
});
更详细的解释:
guildMemberAdd
将在每次有人加入服务器时触发,这将传递 member
对象.user
对象来确定帐户是何时通过 .createdAt
创建的.1000*60*60*24*10
毫秒.role
对象.否则,Guild.roles.get()
是通过 ID 查找角色的好方法.guildMemberAdd
will fire every time someone joins a server, this will pass on the member
object.user
object from that member to determine when the account was created via .createdAt
.1000*60*60*24*10
milliseconds.role
object. Otherwise Guild.roles.get()
is a good way to find a role by its ID.这篇关于Discord.js 帐户创建后的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!