如何从 Discord JDA 中的 discord 标签获取用户?
How do I get a user from their discord tag in Discord JDA?
有没有办法从某人的 discord 标签中找到他的 ID?注:他们在我有ID的某个公会,如果有帮助的话。
假设您的意思是“Name#1234”带有 discord 标签:
直到 this feature request has been implemented by discord you have to use a different approach. If you have all members cached you can simply use Guild#getMemberByTag. Otherwise you have to use Guild#retrieveMembersByPrefix,希望同名用户不超过 100 个:
String name = tag.substring(0, tag.lastIndexOf('#'));
guild.retrieveMembersByPrefix(name, 100).onSuccess(members -> {
Member member = members.stream()
.filter(m -> m.getUser().getAsTag().equals(tag))
.findFirst()
.orElse(null);
if (member != null) {
// use member here, it should be the member with that specific tag
} else {
// there are either more than 100 users with the same name or the member is not int he server
}
});
有没有办法从某人的 discord 标签中找到他的 ID?注:他们在我有ID的某个公会,如果有帮助的话。
假设您的意思是“Name#1234”带有 discord 标签:
直到 this feature request has been implemented by discord you have to use a different approach. If you have all members cached you can simply use Guild#getMemberByTag. Otherwise you have to use Guild#retrieveMembersByPrefix,希望同名用户不超过 100 个:
String name = tag.substring(0, tag.lastIndexOf('#'));
guild.retrieveMembersByPrefix(name, 100).onSuccess(members -> {
Member member = members.stream()
.filter(m -> m.getUser().getAsTag().equals(tag))
.findFirst()
.orElse(null);
if (member != null) {
// use member here, it should be the member with that specific tag
} else {
// there are either more than 100 users with the same name or the member is not int he server
}
});