Skip to content

Instantly share code, notes, and snippets.

@zekroTJA
Created March 15, 2017 13:00
Show Gist options
  • Save zekroTJA/9b444793f205658f87be064d68d955cd to your computer and use it in GitHub Desktop.
Save zekroTJA/9b444793f205658f87be064d68d955cd to your computer and use it in GitHub Desktop.
JDA Discord Bot Tutorial #05: Permissions
package commands;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import core.permsCore;
/**
* © zekro 2017
*
* @author zekro
*/
public class cmdPing implements Command {
@Override
public boolean called(String[] args, MessageReceivedEvent event) {
return false;
}
@Override
public void action(String[] args, MessageReceivedEvent event) {
if (permsCore.check(event) > 1)
return;
event.getTextChannel().sendMessage("Pong!").queue();
}
@Override
public void executed(boolean sucess, MessageReceivedEvent event) {
System.out.println("[INFO] Command '-ping' wurde ausgeführt!");
}
@Override
public String help() {
return null;
}
}
package core;
import net.dv8tion.jda.core.entities.Role;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import util.STATIC;
import java.util.Arrays;
/**
* © zekro 2017
*
* @author zekro
*/
public class permsCore {
public static int check(MessageReceivedEvent event) {
for ( Role r : event.getGuild().getMember(event.getAuthor()).getRoles() ) {
if (Arrays.stream(STATIC.FULLPERMS).parallel().anyMatch(r.getName()::contains))
return 2;
else if (Arrays.stream(STATIC.PERMS).parallel().anyMatch(r.getName()::contains))
return 1;
else
event.getTextChannel().sendMessage(":warning: Sorry, " + event.getAuthor().getAsMention() + ", you don't have the permissions to use this command!").queue();
}
return 0;
}
}
@jokemaleware
Copy link

STATIC gibt es nicht..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment