Discord-JDA:如何获取有关加入服务器的用户的数据?

时间:2018-10-01 00:51:37

标签: java javadoc discord discord-jda

如何为变量User newUser分配登录服务器的用户?

我的程序的一部分:

Main.java

public static void main(String[] args) throws Exception{
    try {
        JDA api = new JDABuilder(AccountType.BOT).setToken(token).build();
        api.addEventListener(new MyEventListener(api));

    } catch (Exception e) {
        e.printStackTrace();
    }
}

MyEventListener.java

public void onMessageReceived(MessageReceivedEvent event) {
    User newUser;
}

我阅读了Javadoc,也许我需要使用GuildMemberJoinEvent。如果这是我的需要,请提供示例代码以帮助如何在我的程序中正确使用此功能,以提供帮助。

1 个答案:

答案 0 :(得分:1)

private static User newUser;

@Override
public void onGuildMemberJoin(GuildMemberJoinEvent event) {

    newUser = event.getUser();

}

@Override
public void onMessageReceived(MessageReceivedEvent event) {

    System.out.println(newUser.getName()); //...your code

}