javascript - Discord - 显示具有指定编号的成员加入位置
问题描述
我想告诉你我在参数中输入的用户数量是加入服务器的顺序。喜欢 = 当我使用时,.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
这个用于显示接合位置的命令,但我很困惑,我该怎么做?
解决方案
尝试这个:
// 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']
.
推荐阅读
- amazon-cognito - 如何保证 amazon-cognito 上的preferred_username 唯一性?
- sql - 创建 VIEW 以获取连接数
- python - 在 PyQt5 中合并插槽
- matlab - 转置矩阵的每一行并将结果向量乘以其他矩阵的更快方法?
- java - Open 1 different activity for each cardview
- windows-10 - CSS:如何将样式表链接从 fonts.google.com 转换为我的 file.css (从外部到内部?
- c++ - 如何在数值积分的不同步骤中添加随机项
- c - 预期在 ARM 中的装配“)”
- python - 与正常执行相比,python 调试器中的 Django QuerySet 延迟评估不同
- reactjs - React typescript Element'不可分配给类型