mirror of
https://github.com/nx-bat/discordbot-ng.git
synced 2026-11-11 07:13:37 -05:00
(buttons): Implement close-ticket button.
This commit is contained in:
@@ -1,13 +1,20 @@
|
|||||||
import { ButtonInteraction, Client, MessageFlags, ChannelType } from 'discord.js';
|
import { ButtonInteraction, Client, MessageFlags, ChannelType } from 'discord.js';
|
||||||
import { Database } from '../shared/Database';
|
import { Database } from '../shared/Database';
|
||||||
|
import { Button } from '../types';
|
||||||
|
|
||||||
export default {
|
class CloseTicketButton implements Button<Client> {
|
||||||
name: 'close-ticket',
|
id = 'close-ticket';
|
||||||
handler: async function (client: Client, interaction: ButtonInteraction) {
|
|
||||||
const channel = await interaction.channel?.fetch();
|
|
||||||
|
|
||||||
if (!channel || !channel.isThread() || !channel.isSendable() || channel.type != ChannelType.PrivateThread)
|
async execute(context: Client<boolean>, interaction: ButtonInteraction, ...args: any[]): Promise<void> {
|
||||||
return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Oops. Something went wrong. Please report this to a staff member.' });
|
if (!interaction.inGuild()) return;
|
||||||
|
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||||
|
|
||||||
|
try {
|
||||||
|
const channel = await context.channels.fetch(interaction.channelId);
|
||||||
|
|
||||||
|
if (!channel) throw new Error("The interaction channel couldn't be fetched.");
|
||||||
|
if (!channel.isThread() || channel.type != ChannelType.PrivateThread) throw new Error('This interaction was not run in a ticket thread.');
|
||||||
|
if (!channel.isSendable()) throw new Error("I don't have permission to send messages in this channel.");
|
||||||
|
|
||||||
await interaction.message.edit({
|
await interaction.message.edit({
|
||||||
content: interaction.message.content,
|
content: interaction.message.content,
|
||||||
@@ -20,9 +27,14 @@ export default {
|
|||||||
|
|
||||||
await interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Ticket closed.' });
|
await interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Ticket closed.' });
|
||||||
|
|
||||||
channel.edit({
|
await channel.edit({
|
||||||
archived: true,
|
archived: true,
|
||||||
locked: true
|
locked: true
|
||||||
});
|
});
|
||||||
|
} catch (error: Error | any) {
|
||||||
|
await interaction.editReply({ content: error.message }).catch(() => {});
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new CloseTicketButton();
|
||||||
Reference in New Issue
Block a user