Search in sources :

Example 1 with Icon

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);
    }
}
Also used : Message(net.dv8tion.jda.api.entities.Message) AccountManager(net.dv8tion.jda.api.managers.AccountManager) Icon(net.dv8tion.jda.api.entities.Icon) IOException(java.io.IOException) File(java.io.File)

Example 2 with Icon

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");
    }
}
Also used : Message(net.dv8tion.jda.api.entities.Message) AccountManager(net.dv8tion.jda.api.managers.AccountManager) Icon(net.dv8tion.jda.api.entities.Icon) IOException(java.io.IOException) File(java.io.File)

Aggregations

File (java.io.File)2 IOException (java.io.IOException)2 Icon (net.dv8tion.jda.api.entities.Icon)2 Message (net.dv8tion.jda.api.entities.Message)2 AccountManager (net.dv8tion.jda.api.managers.AccountManager)2