diff --git a/commands/ticket/add.js b/commands/ticket/add.js index d46338e..61746de 100644 --- a/commands/ticket/add.js +++ b/commands/ticket/add.js @@ -2,6 +2,7 @@ import { SlashCommandBuilder, EmbedBuilder } from 'discord.js'; import ticketState from '../../states/TicketState.js'; import Logger from '../../utils/logger.js'; import { apiFetch } from '../../utils/apiFetch.js'; +import { replyError } from '../../utils/replyError.js'; export const data = new SlashCommandBuilder() .setName('ticket-add') @@ -26,6 +27,7 @@ export const execute = async (interaction) => { } const ticketId = ticketState.getChannelIds()[interaction.channelId]; try { + await interaction.deferReply({ ephemeral: true }); const response = await apiFetch('/ticket', { method: 'GET', query: { @@ -42,10 +44,10 @@ export const execute = async (interaction) => { ticketTeamRoleIds.includes(role.id) ); if (!hasRole) { - await interaction.reply({ - content: 'You dont have the permission to add a user to this ticket.', - ephemeral: true, - }); + await replyError( + interaction, + 'You dont have the permission to add a user to this ticket.' + ); return; } @@ -56,7 +58,7 @@ export const execute = async (interaction) => { const message = await interaction.channel.send(`${user}`); await message.delete(); - await interaction.reply({ + await interaction.editReply({ embeds: [ new EmbedBuilder() .setColor('#f0833a') @@ -66,11 +68,9 @@ export const execute = async (interaction) => { }); } catch (error) { Logger.error(`Could not add user to ticket: ${error}`); - - await interaction.reply({ - content: - 'Could not add the user to this ticket. Please try again later. If this error persists, please report to the staff team.', - ephemeral: true, - }); + await replyError( + interaction, + 'Could not add the user to this ticket. Please try again later. If this error persists, please report to the staff team.' + ); } }; diff --git a/commands/ticket/remove.js b/commands/ticket/remove.js index 6dbc2f5..a77ff95 100644 --- a/commands/ticket/remove.js +++ b/commands/ticket/remove.js @@ -2,6 +2,7 @@ import { SlashCommandBuilder, EmbedBuilder } from 'discord.js'; import ticketState from '../../states/TicketState.js'; import Logger from '../../utils/logger.js'; import { apiFetch } from '../../utils/apiFetch.js'; +import { replyError } from '../../utils/replyError.js'; export const data = new SlashCommandBuilder() .setName('ticket-remove') @@ -26,6 +27,7 @@ export const execute = async (interaction) => { } const ticketId = ticketState.getChannelIds()[interaction.channelId]; try { + await interaction.deferReply({ ephemeral: true }); const response = await apiFetch('/ticket', { method: 'GET', query: { @@ -42,17 +44,16 @@ export const execute = async (interaction) => { ticketTeamRoleIds.includes(role.id) ); if (!hasRole) { - await interaction.reply({ - content: - 'You dont have the permission to remove a user from this ticket.', - ephemeral: true, - }); + await replyError( + interaction, + 'You dont have the permission to remove a user from this ticket.' + ); return; } await interaction.channel.permissionOverwrites.delete(user); - await interaction.reply({ + await interaction.editReply({ embeds: [ new EmbedBuilder() .setColor('#f0833a') @@ -65,10 +66,9 @@ export const execute = async (interaction) => { } catch (error) { Logger.error(`Could not remove user from ticket: ${error}`); - await interaction.reply({ - content: - 'Could not remove user from this ticket. Please try again later. If this error persists, please report to the staff team.', - ephemeral: true, - }); + await replyError( + interaction, + 'Could not remove user from this ticket. Please try again later. If this error persists, please report to the staff team.' + ); } }; diff --git a/events/ticket.js b/events/ticket.js index 86a7946..e1d091e 100644 --- a/events/ticket.js +++ b/events/ticket.js @@ -70,6 +70,7 @@ export const ticketHandler = async (interaction) => { if (action === 'create') { try { + await interaction.deferReply({ ephemeral: true }); const response = await apiFetch('/ticket', { method: 'POST', body: { @@ -80,7 +81,7 @@ export const ticketHandler = async (interaction) => { const ticket = await response.json(); if (response.ok) { ticketState.addChannelId(`${ticket.data.id}`, ticket.data.channel_id); - await interaction.reply({ + await interaction.editReply({ content: `Your ticket has been created: <#${ticket.data.channel_id}>.`, ephemeral: true, }); @@ -105,6 +106,7 @@ export const ticketHandler = async (interaction) => { if (action === 'close') { // close existing ticket try { + await interaction.deferReply({ ephemeral: true }); const confirm = new ButtonBuilder() .setCustomId(`ticket-closeConfirm-${id}`) .setLabel('Confirm') @@ -114,7 +116,7 @@ export const ticketHandler = async (interaction) => { .setColor('#f0833a') .setTitle('Close ticket') .setDescription('Do you want to close this ticket?'); - await interaction.reply({ + await interaction.editReply({ embeds: [embed], components: [row], }); @@ -132,7 +134,8 @@ export const ticketHandler = async (interaction) => { if (action === 'closeConfirm') { // confirm close existing ticket try { - await interaction.reply({ + await interaction.deferReply({ ephemeral: true }); + await interaction.editReply({ content: 'This ticket will be closed.', ephemeral: true, }); diff --git a/tests/commands/ticket/add.test.js b/tests/commands/ticket/add.test.js index 25c4b4c..9892a91 100644 --- a/tests/commands/ticket/add.test.js +++ b/tests/commands/ticket/add.test.js @@ -23,7 +23,9 @@ const interaction = { edit: vi.fn(), }, }, + deferReply: vi.fn(), reply: vi.fn(), + editReply: vi.fn(), member: { roles: { cache: { @@ -73,7 +75,7 @@ it('can execute', async () => { ViewChannel: true, }); - expect(interaction.reply).toBeCalledWith({ + expect(interaction.editReply).toBeCalledWith({ embeds: [ { data: { diff --git a/tests/commands/ticket/remove.test.js b/tests/commands/ticket/remove.test.js index dadb7a1..9b23c3f 100644 --- a/tests/commands/ticket/remove.test.js +++ b/tests/commands/ticket/remove.test.js @@ -18,7 +18,9 @@ const interaction = { delete: vi.fn(), }, }, + deferReply: vi.fn(), reply: vi.fn(), + editReply: vi.fn(), member: { roles: { cache: { @@ -65,7 +67,7 @@ it('can execute', async () => { expect(interaction.channel.permissionOverwrites.delete).toBeCalledWith(user); - expect(interaction.reply).toBeCalledWith({ + expect(interaction.editReply).toBeCalledWith({ embeds: [ { data: {