use of net.dv8tion.jda.core.exceptions.PermissionException in project Ardent by adamint.
the class FancyPlay method noArgs.
@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (args.length > 1) {
AudioManager audioManager = guild.getAudioManager();
String url = message.getRawContent().replace(GuildUtils.getPrefix(guild) + args[0], "");
boolean shouldDeleteMessage = shouldDeleteMessages(guild);
boolean implement = false;
if (!audioManager.isConnected()) {
VoiceChannel success = joinChannel(guild, guild.getMember(user), this, audioManager, channel);
if (success != null) {
loadAndPlay(message, user, this, (TextChannel) channel, url, success, false, false);
implement = true;
}
} else {
loadAndPlay(message, user, this, (TextChannel) sendTo(channel, guild), url, audioManager.getConnectedChannel(), false, false);
implement = true;
}
if (implement) {
if (shouldDeleteMessage) {
try {
message.delete().queue();
} catch (PermissionException ex) {
guild.getOwner().getUser().openPrivateChannel().queue(privateChannel -> {
privateChannel.sendMessage("Auto-deleting music play messages is enabled, " + "but you need to give me the `MANAGE MESSAGES` permission so I can " + "actually delete the messages.").queue();
});
}
}
}
} else
sendTranslatedMessage("You need to specify a song name or URL", channel, user);
}
use of net.dv8tion.jda.core.exceptions.PermissionException in project Ardent by adamint.
the class Botname method noArgs.
@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (args.length == 1) {
sendTranslatedMessage("Enter what you want me to nickname myself", channel, user);
interactiveOperation(channel, message, howLongMessage -> {
String howLong = howLongMessage.getRawContent();
try {
guild.getController().setNickname(guild.getSelfMember(), howLong).queue(aVoid -> {
sendTranslatedMessage("Changed my nickname!", channel, user);
});
} catch (Exception e) {
new BotException(e);
}
});
} else {
String name = message.getContent().replace(GuildUtils.getPrefix(guild) + args[0] + " ", "");
if (name.equalsIgnoreCase("reset")) {
name = "";
}
try {
guild.getController().setNickname(guild.getSelfMember(), name).queue(aVoid -> {
try {
sendTranslatedMessage("Changed my nickname!", channel, user);
} catch (Exception e) {
new BotException(e);
}
});
} catch (PermissionException ex) {
sendTranslatedMessage("I couldn't change my nickname, make sure I have permission to do that", channel, user);
}
}
}
use of net.dv8tion.jda.core.exceptions.PermissionException in project Ardent by adamint.
the class SoftBan method noArgs.
@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
Member userMember = guild.getMember(user);
if (userMember.hasPermission(Permission.BAN_MEMBERS)) {
List<User> mentioned = message.getMentionedUsers();
try {
User u = mentioned.get(0);
String userString = u.toString();
String uToSend = UserUtils.getNameWithDiscriminator(userString);
try {
guild.getController().ban(u, 7).queue();
guild.getController().unban(u).queue();
sendTranslatedMessage("Soft-banned **" + uToSend + "**", channel, user);
} catch (PermissionException ex) {
sendTranslatedMessage("I don't have permissions to ban!", channel, user);
}
} catch (Exception e) {
new BotException(e);
}
} else {
sendTranslatedMessage("You don't have the: `Ban Members` permission", channel, user);
}
}
use of net.dv8tion.jda.core.exceptions.PermissionException in project Ardent by adamint.
the class Prune method noArgs.
@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (args.length == 1) {
sendTranslatedMessage("Prune\n" + "Prune users who have been inactive a certain amount of days\n" + "\n" + "Syntax: {0}prune [amount of days]\n" + "Example usage: {0}prune 4".replace("{0}", GuildUtils.getPrefix(guild) + args[0]), channel, user);
} else {
if (guild.getMember(user).hasPermission(Permission.MANAGE_SERVER)) {
try {
int day = Integer.parseInt(args[1]);
if (day <= 0) {
sendTranslatedMessage("Your number has to be at least 1!", channel, user);
return;
}
guild.getController().prune(day).queue(integer -> {
try {
sendTranslatedMessage("Successfully pruned{0} users.".replace("{0}", String.valueOf(integer)), channel, user);
} catch (Exception e) {
new BotException(e);
}
});
} catch (NumberFormatException ex) {
sendTranslatedMessage("You did not supply a whole number.", channel, user);
} catch (PermissionException ex) {
sendTranslatedMessage("I don't have permissions to kick users", channel, user);
}
} else
sendTranslatedMessage("You don't have permission to kick users.", channel, user);
}
}
Aggregations