Search in sources :

Example 1 with AccountManagerUpdatable

use of net.dv8tion.jda.core.managers.AccountManagerUpdatable in project Saber-Bot by notem.

the class AvatarCommand method action.

@Override
public void action(String head, String[] args, MessageReceivedEvent event) {
    AccountManagerUpdatable manager = Main.getShardManager().getJDA().getSelfUser().getManagerUpdatable();
    if (event.getMessage().getAttachments().isEmpty())
        return;
    Message.Attachment attachment = event.getMessage().getAttachments().get(0);
    try {
        File file = new File(attachment.getFileName());
        attachment.download(file);
        Icon icon = Icon.from(file);
        manager.getAvatarField().setValue(icon).update().complete();
        MessageUtilities.sendPrivateMsg("Updated bot avatar!", event.getAuthor(), null);
        file.delete();
    } catch (IOException e) {
        Logging.exception(this.getClass(), e);
        MessageUtilities.sendPrivateMsg("Failed to update bot avatar!", event.getAuthor(), null);
    }
}
Also used : AccountManagerUpdatable(net.dv8tion.jda.core.managers.AccountManagerUpdatable) Message(net.dv8tion.jda.core.entities.Message) Icon(net.dv8tion.jda.core.entities.Icon) IOException(java.io.IOException) File(java.io.File)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 Icon (net.dv8tion.jda.core.entities.Icon)1 Message (net.dv8tion.jda.core.entities.Message)1 AccountManagerUpdatable (net.dv8tion.jda.core.managers.AccountManagerUpdatable)1