且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

您如何在服务器中找到您的加入位置

更新时间:2023-02-04 13:21:58

您可以使用

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);