mirror of
https://github.com/nx-bat/discordbot-ng.git
synced 2026-11-11 07:13:37 -05:00
(buttons): Implement private-help button.
This commit is contained in:
@@ -1,20 +1,30 @@
|
|||||||
import { ButtonInteraction, Client, ModalBuilder, TextInputStyle, MessageFlags } from 'discord.js';
|
import { ButtonInteraction, Client, ModalBuilder, TextInputStyle, MessageFlags } from 'discord.js';
|
||||||
|
import { Button } from '../types';
|
||||||
import { canOpenPrivateHelpTicket, createTextInput } from '../utils';
|
import { canOpenPrivateHelpTicket, createTextInput } from '../utils';
|
||||||
|
|
||||||
export default {
|
class PrivateHelpButton implements Button<Client> {
|
||||||
name: 'private-help',
|
id = 'private-help';
|
||||||
handler: async function (client: Client, interaction: ButtonInteraction) {
|
|
||||||
if (!(await canOpenPrivateHelpTicket(interaction.user.id)))
|
async execute(context: Client<boolean>, interaction: ButtonInteraction, ...args: any[]): Promise<void> {
|
||||||
return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'You can only have one open ticket at a time that is less than a day old.' });
|
try {
|
||||||
|
if (!await canOpenPrivateHelpTicket(interaction.user.id))
|
||||||
|
throw new Error('You can only have one open ticket at a time that is less than a day old.');
|
||||||
|
|
||||||
const modal = new ModalBuilder()
|
const modal = new ModalBuilder()
|
||||||
.setCustomId('open-ticket-modal')
|
.setCustomId('open-ticket-modal')
|
||||||
.setTitle('Get in contact');
|
.setTitle('Get in contact');
|
||||||
|
|
||||||
const label = createTextInput('ticket-message', 'What is the reason for your ticket?', null, true, TextInputStyle.Paragraph, 1500, 10);
|
const label = createTextInput('ticket-message', 'What is the reason for your ticket?', null, true, TextInputStyle.Paragraph, 1500, 10);
|
||||||
|
|
||||||
modal.addLabelComponents(label);
|
modal.addLabelComponents(label);
|
||||||
|
|
||||||
await interaction.showModal(modal);
|
await interaction.showModal(modal);
|
||||||
|
} catch (error: Error | any) {
|
||||||
|
await interaction.reply({
|
||||||
|
content: error.message,
|
||||||
|
flags: MessageFlags.Ephemeral,
|
||||||
|
}).catch(() => {});
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new PrivateHelpButton();
|
||||||
Reference in New Issue
Block a user