HidekoBot/src/main/java/wtf/beatrice/hidekobot/commands/slash/InviteCommand.java

50 lines
1.8 KiB
Java
Raw Normal View History

2022-11-20 18:56:57 +01:00
package wtf.beatrice.hidekobot.commands.slash;
2022-11-20 16:07:04 +01:00
2022-11-21 16:11:16 +01:00
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageEmbed;
2022-11-20 16:20:50 +01:00
import net.dv8tion.jda.api.entities.channel.ChannelType;
2022-11-20 16:07:04 +01:00
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
2022-11-21 16:11:16 +01:00
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.requests.restaction.WebhookMessageEditAction;
2022-11-20 16:20:50 +01:00
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction;
2022-11-20 16:07:04 +01:00
import org.jetbrains.annotations.NotNull;
import wtf.beatrice.hidekobot.commands.base.Invite;
2022-11-22 16:41:08 +01:00
import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl;
2022-11-20 16:07:04 +01:00
public class InviteCommand extends SlashCommandImpl
2022-11-20 16:07:04 +01:00
{
@Override
public CommandData getSlashCommandData()
{
return Commands.slash("invite", "Get an invite link for the bot.");
}
@Override
public void runSlashCommand(@NotNull SlashCommandInteractionEvent event)
2022-11-20 16:07:04 +01:00
{
2022-11-21 16:11:16 +01:00
// defer reply because this might take a moment
ReplyCallbackAction replyCallbackAction = event.deferReply();
2022-11-20 16:20:50 +01:00
// only make message permanent in DMs
2022-11-21 16:11:16 +01:00
if(event.getChannelType() != ChannelType.PRIVATE)
2022-11-20 16:20:50 +01:00
{
2022-11-21 16:11:16 +01:00
replyCallbackAction = replyCallbackAction.setEphemeral(true);
2022-11-20 16:20:50 +01:00
}
2022-11-21 16:11:16 +01:00
replyCallbackAction.queue();
MessageEmbed inviteEmbed = Invite.generateEmbed();
Button inviteButton = Invite.getInviteButton();
2022-11-21 16:11:16 +01:00
WebhookMessageEditAction<Message> reply =
event.getHook()
.editOriginalEmbeds(inviteEmbed)
.setActionRow(inviteButton);
2022-11-20 16:20:50 +01:00
reply.queue();
2022-11-20 16:07:04 +01:00
}
}