Reputation: 33
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.
Upvotes: 1
Views: 8576
Reputation: 615
Use the .createdAt
property of User to determine their account age
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);
}
});
More detailed explanation:
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.Upvotes: 2