如果用户注册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模板网!
discord.js v12:我如何等待 DM 频道中的消息?discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 频道中的消息?)
如何让我的机器人提及发出该机器人命令的人how to make my bot mention the person who gave that bot command(如何让我的机器人提及发出该机器人命令的人)
如何修复必须使用导入来加载 ES 模块 discord.jsHow to fix Must use import to load ES Module discord.js(如何修复必须使用导入来加载 ES 模块 discord.js)
如何列出来自特定服务器的所有成员?How to list all members from a specific server?(如何列出来自特定服务器的所有成员?)
Discord bot:修复“找不到 FFMPEG"Discord bot: Fix ‘FFMPEG not found’(Discord bot:修复“找不到 FFMPEG)
使用 discord.js 加入 discord 服务器时的欢迎消息Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服务器时的欢迎消息)