我想按名称赋予该用户角色。 所以我想通过用户名获取ID。
let role = message.guild.roles.find('name', 'TESTrole');
let id = client.users.get("name", "TESTname");
let member = message.member.guild.members.get(id);
member.addRole(role);
答案 0 :(得分:5)
您可以使用find()
方法。
let user = client.users.find("username", "TESTname");
//OR
let user = client.users.find(user => user.username == "TESTname");
//once you've found the user you can get the id (or you can write .id after the find method)
let id = user.id;
答案 1 :(得分:5)
旧帖子(我知道),但对使用 v12 的人发表评论,
const user = client.users.cache.find(user => user.username == "").id;
答案 2 :(得分:-1)