Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions commands/ticket/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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: {
Expand All @@ -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;
}

Expand All @@ -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')
Expand All @@ -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.'
);
}
};
22 changes: 11 additions & 11 deletions commands/ticket/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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: {
Expand All @@ -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')
Expand All @@ -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.'
);
}
};
9 changes: 6 additions & 3 deletions events/ticket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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,
});
Expand All @@ -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')
Expand All @@ -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],
});
Expand All @@ -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,
});
Expand Down
4 changes: 3 additions & 1 deletion tests/commands/ticket/add.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const interaction = {
edit: vi.fn(),
},
},
deferReply: vi.fn(),
reply: vi.fn(),
editReply: vi.fn(),
member: {
roles: {
cache: {
Expand Down Expand Up @@ -73,7 +75,7 @@ it('can execute', async () => {
ViewChannel: true,
});

expect(interaction.reply).toBeCalledWith({
expect(interaction.editReply).toBeCalledWith({
embeds: [
{
data: {
Expand Down
4 changes: 3 additions & 1 deletion tests/commands/ticket/remove.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const interaction = {
delete: vi.fn(),
},
},
deferReply: vi.fn(),
reply: vi.fn(),
editReply: vi.fn(),
member: {
roles: {
cache: {
Expand Down Expand Up @@ -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: {
Expand Down