(buttons): Hook up buttons. Pre-testing.

This commit is contained in:
2026-10-14 12:18:35 +08:00
parent 12cdba21b5
commit 71e2d1c088
15 changed files with 42 additions and 16 deletions
@@ -5,7 +5,7 @@ import { Button } from '../types';
class ClaimTicketButton implements Button<Client> {
id = 'claim-ticket';
async execute(context: Client<boolean>, interaction: ButtonInteraction, ...args: any[]): Promise<void> {
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
if (!interaction.inGuild()) return;
await interaction.deferReply({ flags: [MessageFlags.Ephemeral] });
@@ -4,7 +4,7 @@ import { Button } from '../types';
class CloseModTicketButton implements Button<Client> {
id = 'close-mod-ticket';
async execute(context: Client<boolean>, interaction: ButtonInteraction, ...args: any[]): Promise<void> {
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
if (!interaction.inGuild()) return;
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
@@ -5,7 +5,7 @@ import { Button } from '../types';
class CloseTicketButton implements Button<Client> {
id = 'close-ticket';
async execute(context: Client<boolean>, interaction: ButtonInteraction, ...args: any[]): Promise<void> {
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
if (!interaction.inGuild()) return;
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
@@ -5,7 +5,7 @@ import { Button } from '../types';
class DevWatchButton implements Button<Client> {
id = 'dev-watch';
async execute(context: Client<boolean>, interaction: ButtonInteraction, ...args: any[]): Promise<void> {
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
if (!interaction.inGuild()) return;
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
+27
View File
@@ -0,0 +1,27 @@
import claimTicket from "./claimTicket";
import closeModTicket from "./closeModTicket";
import closeTicket from "./closeTicket";
import devWatch from "./devWatch";
import noteNext from "./noteNext";
import notePrevious from "./notePrevious";
import openTicketForReportedMessage from "./openTicketForReportedMessage";
import privateHelp from "./privateHelp";
import recordsNext from "./recordsNext";
import recordsPrevious from "./recordsPrevious";
import roleButton from "./roleButton";
import unclaimTicket from "./unclaimTicket";
export default [
claimTicket,
closeModTicket,
closeTicket,
devWatch,
noteNext,
notePrevious,
openTicketForReportedMessage,
privateHelp,
recordsNext,
recordsPrevious,
roleButton,
unclaimTicket
];
@@ -5,7 +5,7 @@ import { createPrivateHelpTicketThread } from '../utils';
class OpenTicketForReportedMessageButton implements Button<Client> {
id = 'open-ticket-for-reported-message';
async execute(context: Client<boolean>, interaction: ButtonInteraction, ...args: any[]): Promise<void> {
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
if (!interaction.inGuild()) return;
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
@@ -5,7 +5,7 @@ import { canOpenPrivateHelpTicket, createTextInput } from '../utils';
class PrivateHelpButton implements Button<Client> {
id = 'private-help';
async execute(context: Client<boolean>, interaction: ButtonInteraction, ...args: any[]): Promise<void> {
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
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.');
@@ -5,7 +5,7 @@ import { Button } from '../types';
class RoleButtonButton implements Button<Client> {
id = 'role-button';
async execute(context: Client<boolean>, interaction: ButtonInteraction, ...args: any[]): Promise<void> {
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
if (!interaction.inGuild()) return;
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
@@ -5,7 +5,7 @@ import { Button } from '../types';
class UnclaimTicketButton implements Button<Client> {
id = 'unclaim-ticket';
async execute(context: Client<boolean>, interaction: ButtonInteraction, ...args: any[]): Promise<void> {
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
if (!interaction.inGuild()) return;
await interaction.deferReply();
+6 -7
View File
@@ -1,4 +1,5 @@
import { Client, GatewayIntentBits, MessageFlags, Partials } from 'discord.js';
import buttons from './buttons';
import { config } from './config';
import events from './events';
import { Database } from './shared/Database';
@@ -37,7 +38,6 @@ const client = new Client({
const commands: Handler[] = [];
const contextMenus: Handler[] = [];
const buttons: Handler[] = [];
const modals: Handler[] = [];
const menus: Handler[] = [];
@@ -93,10 +93,11 @@ client.on('interactionCreate', async (interaction) => {
const id = interaction.customId.split('_')[0];
for (const button of buttons) {
if (id == button.name) {
button.handler(client, interaction, ...interaction.customId.split('_').slice(1));
return;
}
if (button.id != id) continue;
Promise.resolve((button.execute as (context: Client, ...args: unknown[]) => Promise<void>)(client, ...interaction.customId.split('_').slice(1))
.catch(e => console.error('An error occurred while handling a button interaction: ', e)));
return;
}
} else if (interaction.isModalSubmit()) {
// Handle modal submissions.
@@ -126,14 +127,12 @@ client.on('clientReady', async () => {
await loadHandlersFrom('commands', commands);
await loadHandlersFrom('context-menus', contextMenus);
await loadHandlersFrom('buttons', buttons);
await loadHandlersFrom('modals', modals);
await loadHandlersFrom('menus', menus);
await refreshCommands(client);
await initIfNecessary(client, commands);
await initIfNecessary(client, buttons);
await initIfNecessary(client, modals);
await initIfNecessary(client, menus);
+1 -1
View File
@@ -2,5 +2,5 @@ import { ButtonInteraction } from "discord.js";
export interface Button<Context> {
id: string;
execute(context: Context, interaction: ButtonInteraction, ...args: any[]): Promise<void>;
execute(context: Context, interaction: ButtonInteraction, ...args: any): Promise<void>;
}