【问题标题】:Discord - showing member join position with specified numberDiscord - 显示具有指定编号的成员加入位置
【发布时间】:2020-06-28 03:33:48
【问题描述】:
我想告诉你我在参数中输入的用户数是加入服务器的顺序。喜欢 = 当我使用 .join 1 时,我想显示第一个成员加入服务器。我用
let arr = message.guild.members.filter(a => !a.user.bot).array().sort((b, a) => b.joinedTimestamp - a.joinedTimestamp)
let map = arr.indexOf(sesmi) + 1
这个显示接合位置的命令,但我很困惑,我该怎么做?
【问题讨论】:
标签:
javascript
discord
discord.js
【解决方案1】:
试试这个:
// if the first argument is not a number (this message is kind of bad so you can change it)
if (isNaN(args[0])) return message.reply('you must specify what number user you want to get!')
const members = message.guild.members.cache
.filter(member => !member.user.bot)
// sorted is a member on Discord's utility class Collection that doesn't modify the original collection
.sorted((a, b) => a.joinedTimestamp - b.joinedTimestamp)
.array()
// the number user to get
const n = Number(args[0])
// if there are not enough members
if (n > members.length) {
// You only really need this if there is ever going to be only 1 member in the server
// and if you care about grammar. You could also just do
// return message.reply(`there are only ${members.length} members!`)
const plural = members.length !== 1
return message.reply(`there ${plural ? 'are' : 'is'} only ${members.length} member${plural ? 's' : ''}!`)
}
message.channel.send(members[n - 1].user.tag)
我假设 args 将是一个字符串数组,其参数传递到命令中(例如,.join 1 将具有 args ['1']。