Javascript Discord.js如何仅从用户名获取用户id

Javascript Discord.js如何仅从用户名获取用户id,javascript,node.js,discord,discord.js,Javascript,Node.js,Discord,Discord.js,这不起作用: client.users.cache.get(`${args[0]}').id 我该怎么做才能修好它?我在v12上试试看 matching_client = client.users.cache.filter(user => user.username === args[0]); matching\u client是与该用户名匹配的用户的集合 相关文档链接: 这有帮助吗?它返回以下错误消息:TypeError:message.client.users.find不是一个函数这

这不起作用:
client.users.cache.get(`${args[0]}').id

我该怎么做才能修好它?我在v12上

试试看

matching_client = client.users.cache.filter(user => user.username === args[0]);
matching\u client
是与该用户名匹配的用户的集合

相关文档链接:


这有帮助吗?它返回以下错误消息:
TypeError:message.client.users.find不是一个函数
这可以正常工作,但如何使它只使用id?我尝试了
votefor=message.client.users.cache.filter(user=>user.username==args[0]);id=votefor.id
但返回unfinedy您必须从集合中获取第一个元素,请尝试
id=votefor.array()[0].id
,这有点不必要,为什么不只是user
.find()
?这样,您就不必将其转换为数组,也不必按0对其进行索引。