-
-
Save zekroTJA/9b444793f205658f87be064d68d955cd to your computer and use it in GitHub Desktop.
JDA Discord Bot Tutorial #05: Permissions
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 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; | |
} | |
} |
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 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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
STATIC gibt es nicht..