简体   繁体   English

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

[英]Discord.js how to get user id just from the username

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

What should I do to fix it?我应该怎么做才能解决它? I'm on v12我在v12

Try尝试

matching_client = client.users.cache.filter(user => user.username === args[0]);

matching_client is a Collection of users that match that username matching_client是与该用户名匹配的用户集合

Relevant documentation link:相关文档链接:

https://discord.js.org/#/docs/collection/master/class/Collection?scrollTo=filter https://discord.js.org/#/docs/collection/master/class/Collection?scrollTo=filter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM