mirror of
https://github.com/nx-bat/discordbot-ng.git
synced 2026-11-11 07:13:37 -05:00
(buttons): Implement close-mod-ticket button & fix claim-ticket.
This commit is contained in:
@@ -7,6 +7,7 @@ class ClaimTicketButton implements Button<Client> {
|
||||
|
||||
async execute(context: Client<boolean>, interaction: ButtonInteraction, ...args: any[]): Promise<void> {
|
||||
if (!interaction.inGuild()) return;
|
||||
await interaction.deferReply({ flags: [MessageFlags.Ephemeral] });
|
||||
|
||||
try {
|
||||
const channel = await context.channels.fetch(interaction.channelId);
|
||||
@@ -17,7 +18,10 @@ class ClaimTicketButton implements Button<Client> {
|
||||
|
||||
const settings = await Database.getOrCreateSettings(interaction.guildId);
|
||||
if (!settings.private_help_role_id) throw new Error("\`private_help_role_id\` hasn't been configured. Please report this error to staff.");
|
||||
if (!(interaction.member.roles as string[]).includes(settings.private_help_role_id)) throw new Error("You don't have permission to claim tickets.");
|
||||
|
||||
const guild = await context.guilds.fetch(interaction.guildId);
|
||||
const member = await guild.members.fetch(interaction.user.id);
|
||||
if (!member.roles.cache.has(settings.private_help_role_id)) throw new Error("You don't have permission to claim tickets.");
|
||||
|
||||
const closeButton = new ButtonBuilder()
|
||||
.setCustomId('close-ticket')
|
||||
@@ -36,14 +40,9 @@ class ClaimTicketButton implements Button<Client> {
|
||||
components: [row]
|
||||
});
|
||||
|
||||
await interaction.reply({ content: `Ticket claimed by ${interaction.user}.` });
|
||||
await interaction.editReply({ content: `Ticket claimed by ${interaction.user}.` });
|
||||
} catch (error: Error | any) {
|
||||
await interaction.reply({
|
||||
content: error.message,
|
||||
flags: MessageFlags.Ephemeral,
|
||||
}).catch(() => {});
|
||||
|
||||
return;
|
||||
await interaction.editReply({ content: error.message }).catch(() => {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
import { ButtonInteraction, Client, MessageFlags, ChannelType, PermissionFlagsBits } from 'discord.js';
|
||||
import { ButtonInteraction, Client, MessageFlags, ChannelType } from 'discord.js';
|
||||
import { Button } from '../types';
|
||||
|
||||
export default {
|
||||
name: 'close-mod-ticket',
|
||||
handler: async function (client: Client, interaction: ButtonInteraction) {
|
||||
await interaction.deferReply({ flags: [MessageFlags.Ephemeral] });
|
||||
const channel = await interaction.channel?.fetch();
|
||||
const guild = await interaction.guild?.fetch();
|
||||
const member = await guild?.members.fetch(interaction.user.id);
|
||||
class CloseModTicketButton implements Button<Client> {
|
||||
id = 'close-mod-ticket';
|
||||
|
||||
if (!channel || !channel.isThread() || !channel.isSendable() || channel.type != ChannelType.PrivateThread || !member)
|
||||
return interaction.editReply({ content: 'Oops. Something went wrong. Please report this to a staff member.' });
|
||||
async execute(context: Client<boolean>, interaction: ButtonInteraction, ...args: any[]): Promise<void> {
|
||||
if (!interaction.inGuild()) return;
|
||||
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||
|
||||
if (!member.permissions.has(PermissionFlagsBits.KickMembers))
|
||||
return interaction.editReply({ content: 'Only staff members may close mod tickets.' });
|
||||
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.");
|
||||
|
||||
if (!interaction.memberPermissions.has('KickMembers')) throw new Error("You don't have permission to close this ticket.");
|
||||
|
||||
await interaction.message.edit({
|
||||
content: interaction.message.content,
|
||||
@@ -23,9 +26,14 @@ export default {
|
||||
|
||||
await interaction.editReply({ content: 'Ticket closed.' });
|
||||
|
||||
channel.edit({
|
||||
await channel.edit({
|
||||
archived: true,
|
||||
locked: true
|
||||
});
|
||||
} catch (error: Error | any) {
|
||||
await interaction.editReply({ content: error.message }).catch(() => {});
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default new CloseModTicketButton();
|
||||
Reference in New Issue
Block a user