Fixed logging and saying hi to the bot channel

This commit is contained in:
Norbi Peti 2016-10-03 22:16:08 +02:00
parent 842f8a63b7
commit b94a689a1e
3 changed files with 36 additions and 1 deletions

View file

@ -128,5 +128,12 @@
<!-- <classifier>shaded</classifier> --> <!-- Include this line if you want a shaded jar (all the Discord4J dependencies
bundled into one jar) -->
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-jdk14 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.21</version>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,13 @@
package buttondevteam.discordplugin;
import sx.blah.discord.api.events.IListener;
import sx.blah.discord.handle.impl.events.MessageReceivedEvent;
public class CommandListener implements IListener<MessageReceivedEvent> {
@Override
public void handle(MessageReceivedEvent event) {
System.out.println(event.getMessage().getContent());
}
}

View file

@ -6,12 +6,17 @@ import org.bukkit.plugin.java.JavaPlugin;
import com.google.common.base.Charsets;
import sx.blah.discord.api.*;
import sx.blah.discord.api.events.IListener;
import sx.blah.discord.handle.impl.events.ReadyEvent;
import sx.blah.discord.util.DiscordException;
import sx.blah.discord.util.MissingPermissionsException;
import sx.blah.discord.util.RateLimitException;
/**
* Hello world!
*
*/
public class DiscordPlugin extends JavaPlugin {
public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
@Override
public void onEnable() {
try {
@ -19,9 +24,19 @@ public class DiscordPlugin extends JavaPlugin {
ClientBuilder cb = new ClientBuilder();
cb.withToken(IOUtils.toString(getClass().getResourceAsStream("/Token.txt"), Charsets.UTF_8));
IDiscordClient dc = cb.login();
dc.getDispatcher().registerListener(this);
} catch (Exception e) {
e.printStackTrace();
Bukkit.getPluginManager().disablePlugin(this);
}
}
@Override
public void handle(ReadyEvent event) {
try {
event.getClient().getGuilds().get(0).getChannelsByName("bot").get(0).sendMessage("Hi");
} catch (Exception e) {
e.printStackTrace();
}
}
}