-
-
Save zekroTJA/0f06b352e1c336e0d9cc100e7f8d7c89 to your computer and use it in GitHub Desktop.
JDA Discord Bot Tutorial #02: Listeners
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// public class Main() {... | |
//public static void main(String[] Args) {...} | |
public static void addListeners() { | |
builder.addListener(new readyListener()); | |
builder.addListener(new voiceListener()); | |
} | |
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package listeners; | |
import net.dv8tion.jda.core.entities.Guild; | |
import net.dv8tion.jda.core.events.ReadyEvent; | |
import net.dv8tion.jda.core.hooks.ListenerAdapter; | |
/** | |
* © zekro 2017 | |
* | |
* @author zekro | |
*/ | |
public class readyListener extends ListenerAdapter { | |
public void onReady(ReadyEvent event) { | |
String out = "\nThis bot is running on following servers: \n"; | |
for (Guild g : event.getJDA().getGuilds() ) { | |
out += g.getName() + " (" + g.getId() + ") \n"; | |
} | |
System.out.println(out); | |
for (Guild g : event.getJDA().getGuilds() ) { | |
g.getTextChannels().get(0).sendMessage( | |
"Hey guys! Im back again!" | |
).queue(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package listeners; | |
import net.dv8tion.jda.core.events.guild.voice.GuildVoiceJoinEvent; | |
import net.dv8tion.jda.core.hooks.ListenerAdapter; | |
/** | |
* © zekro 2017 | |
* | |
* @author zekro | |
*/ | |
public class voiceListener extends ListenerAdapter { | |
public void onGuildVoiceJoin(GuildVoiceJoinEvent event) { | |
event.getGuild().getTextChannelsByName("voicelog", true).get(0).sendMessage( | |
"Member " + event.getVoiceState().getMember().getUser().getName() + " joined voice channel " + event.getChannelJoined().getName() + "." | |
).queue(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment