use of net.dv8tion.jda.api.entities.Icon in project Saber-Bot by notem.
the class AvatarCommand method action.
@Override
public void action(String head, String[] args, MessageReceivedEvent event) {
AccountManager manager = Main.getShardManager().getJDA().getSelfUser().getManager();
if (event.getMessage().getAttachments().isEmpty())
return;
Message.Attachment attachment = event.getMessage().getAttachments().get(0);
try {
File file = new File(attachment.getFileName());
attachment.downloadToFile(file);
Icon icon = Icon.from(file);
manager.setAvatar(icon).complete();
MessageUtilities.sendPrivateMsg("Updated bot avatar!", event.getAuthor(), null);
if (!file.delete()) {
file.deleteOnExit();
}
} catch (IOException e) {
Logging.exception(this.getClass(), e);
MessageUtilities.sendPrivateMsg("Failed to update bot avatar!", event.getAuthor(), null);
}
}
use of net.dv8tion.jda.api.entities.Icon in project Vinny by kikkia.
the class AvatarCommand method executeCommand.
@Override
protected void executeCommand(CommandEvent commandEvent) {
if (commandEvent.getMessage().getAttachments().isEmpty()) {
commandEvent.reply(commandEvent.getClient().getWarning() + " You need to give a picture attachment.");
return;
}
Message.Attachment attachment = commandEvent.getMessage().getAttachments().get(0);
try {
File file = new File(attachment.getFileName());
attachment.downloadToFile(file);
Icon icon = Icon.from(file);
AccountManager manager = commandEvent.getSelfUser().getManager();
manager.setAvatar(icon).queue();
commandEvent.reply(commandEvent.getClient().getSuccess() + " Successfully updated the avatar");
file.delete();
} catch (IOException e) {
commandEvent.reply(commandEvent.getClient().getError() + " Failed to update the avatar");
}
}
Aggregations