How to turn arg or string into User?

19
January 11, 2019, at 09:40 AM

I am making a command and I need to get a list of roles for a user, the problem is that an argument is a string and getMember() expects a User. How do I turn a string into a User or is there just a better way?

I have trouble shooted with my friends trying various methods. Honestly at this point I can't remember what we have tried.

else if(args[0].equalsIgnoreCase(MeatBotMain.prefix + "getuserroles")) {
            Guild server = event.getGuild();
            String userName = args[1];
            Member user = server.getMember(userName);
            List<Role> userRoles = user.getRoles();
        }

I wasn't expecting it to be so hard to get the mentioned user I thought it would just work first try.

Answer 1

If you only has an username, which is not unique, the Guild class has methods:

List<Member> getMembersByName(String name, boolean ignoreCase);
List<Member> getMembersByNickname(String nickname, boolean ignoreCase);
List<Member> getMembersByEffectiveName(String name, boolean ignoreCase);

that you can try.

READ ALSO
PDFBox: do PDDocument and PDPage have references to one another?

PDFBox: do PDDocument and PDPage have references to one another?

Does a PDPage object contains a reference to the PDDocument to which it belongs? In other words, does a PDPage has knowledge of its PDDocument? Somewhere in the application I have a list of PDDocumentsThese documents get merged into one new PDDocument:

25
How to send youtube-dl stdout to browser to save as a file?

How to send youtube-dl stdout to browser to save as a file?

I am making a php frontend for youtube-dlI am getting stdout from youtube-dl

16
Get the required fields for Google Tag Manager

Get the required fields for Google Tag Manager

I am currently integrating a google tag manager in one of my Silverstripe websites and I require to programatially retrieve details of Product name, order total price and currencyI have retrieved the other details like order id, coupon code but I am unable...

43
Get Value From Ajax in C#

Get Value From Ajax in C#

In PHP I can get value from ajax with this code: $order = $_GET['order']

26