Discord-JDA:如何获取有关加入服务器的用户的数据?
Discord-JDA: How to get data about the user who joined the server?
如何为变量 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
。如果这是我所需要的,那么请通过提供示例代码来帮助我如何为我的程序正确使用此功能。
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
}
如何为变量 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
。如果这是我所需要的,那么请通过提供示例代码来帮助我如何为我的程序正确使用此功能。
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
}