你如何在服务器中找到你的加入位置 [英] How do you find your join position in a server

查看:17
本文介绍了你如何在服务器中找到你的加入位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找一种方法来查找您何时按职位加入服务器.
例如:如果我是服务器的所有者,我将是 1,因为我先加入,然后如果我在所有者之后加入,我将是 2,如果我在 20 人加入之后加入,我将是 21,依此类推.
有谁知道如何在 Node.Js 中解决这个问题?

Looking for a way to find when you joined a server by position.
For example: If I'm the owner of the server I would be 1 because I joined first, then if I joined after the Owner I would be 2 and if I joined after 20 people join I would be 21 and so on.
Does anyone know a way to figure this out in Node.Js?

推荐答案

你可以使用 GuildMember.joinedAt 属性:这将返回您加入服务器的日期.
这是一个可以帮助您的函数:

You can use the GuildMember.joinedAt property: that will return the date of when you joined the server.
Here's a function that can help you:

function getJoinRank(ID, guild) { // Call it with the ID of the user and the guild
    if (!guild.member(ID)) return; // It will return undefined if the ID is not valid

    let arr = guild.members.array(); // Create an array with every member
    arr.sort((a, b) => a.joinedAt - b.joinedAt); // Sort them by join date

    for (let i = 0; i < arr.length; i++) { // Loop though every element
      if (arr[i].id == ID) return i; // When you find the user, return it's position
    }
}

你也可以让它返回数组,如果它对你更好的话.您也可以直接对成员的集合本身进行排序,但请记住,您必须每次都对其进行排序(客户端可以对其进行更新):

You can also make it return the array, if it's better for you. You could also directly sort the members' collection itself, but remember that you'll have to sort it every time (the client could update it):

guild.members.sort((a, b) => a.joinedAt - b.joinedAt);

这篇关于你如何在服务器中找到你的加入位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆