apps/bot/src/components/buttons/newTicket.ts (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import { Result } from "@sapphire/result";
import * as actions from "@/commands/tickets/actions";
import { errorMessage, PublicError } from "@/lib";
import { kitten } from "@/client";
export const newTicketButton = kitten.button("open-ticket", {
run: async (interaction) => {
if (!interaction.guild)
return errorMessage(interaction, "You must run this command in a guild");
const func = actions.createTicket(interaction.member ?? interaction.user, interaction.guild);
const ticketResult = await Result.fromAsync(async () => func);
if (ticketResult.isErr()) {
const error = ticketResult.unwrapErr();
if (error instanceof PublicError) {
return errorMessage(interaction, error.message);
} else {
console.error(error);
return errorMessage(interaction, "An unexpected error occurred while creating the ticket.");
}
}
const { channelId } = ticketResult.unwrap();
return interaction.reply({
content: `Opened ticket <#${channelId}>.`,
flags: ["Ephemeral"],
});
},
});
|