Discord.js days since account creation(Discord.js 帐户创建后的天数)
问题描述
如果用户注册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
创建的. - 时间戳以毫秒为单位存储,因此 10 天相当于
1000*60*60*24*10
毫秒. - 比较这两个时间戳,如果他们的帐户年龄较低,那么你就给他们一个角色.
- 我们假设您已经拥有
role
对象.否则,Guild.roles.get()
是通过 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.
这篇关于Discord.js 帐户创建后的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Discord.js 帐户创建后的天数


- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07