add avatar command

This commit is contained in:
Lee
2024-06-26 02:46:27 +01:00
parent 47beff752c
commit aec2fe1c2b
6 changed files with 42 additions and 5 deletions

View File

@ -0,0 +1,41 @@
package cc.fascinated.bat.command.impl;
import cc.fascinated.bat.command.BatCommand;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
import lombok.NonNull;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
import org.springframework.stereotype.Component;
/**
* @author Fascinated (fascinated7)
*/
@Component
public class AvatarCommand extends BatCommand {
public AvatarCommand() {
super("avatar", "Gets the avatar of a user");
super.addOption(OptionType.USER, "user", "The user to get the avatar of", true);
}
@Override
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
OptionMapping userOption = interaction.getOption("user");
if (userOption == null) {
interaction.reply("You must provide a user to get the avatar of!").queue();
return;
}
User target = userOption.getAsUser();
interaction.replyEmbeds(EmbedUtils.genericEmbed()
.setAuthor("%s's Avatar".formatted(target.getName()), null, target.getEffectiveAvatarUrl())
.setImage(target.getAvatar().getUrl(4096))
.build()
).queue();
}
}