您如何在服务器中找到您的加入位置 [英] How do you find your join position in a server
问题描述
寻找一种按位置查找何时加入服务器的方法.
例如:如果我是服务器的所有者,因为我先加入,所以我将是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?
推荐答案
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屋!