@@ -7,6 +7,7 @@ import { inlineCode } from "@discordjs/formatters";
77import { REST } from "@discordjs/rest" ;
88import { WebSocketManager } from "@discordjs/ws" ;
99import * as TOML from "@ltd/j-toml" ;
10+ import type { APIContainerComponent } from "discord-api-types/v10" ;
1011import {
1112 ApplicationCommandOptionType ,
1213 ApplicationCommandType ,
@@ -105,14 +106,7 @@ client.on(GatewayDispatchEvents.ThreadCreate, async ({ data: channel }) => {
105106 supportThreadParents . set ( channel . id , channel . parent_id ) ;
106107} ) ;
107108
108- client . on ( GatewayDispatchEvents . MessageCreate , async ( { data : message } ) => {
109- const parent = supportThreadParents . get ( message . channel_id ) ;
110- if ( message . id !== message . channel_id || ! parent || ! ASSISTCHANNELS . includes ( parent ) ) {
111- return ;
112- }
113-
114- supportThreadParents . delete ( message . channel_id ) ;
115-
109+ function getComponent ( parent ?: string | null , lock = false ) {
116110 const parts : string [ ] = [ ] ;
117111 if ( parent === SUPPORT_CHANNEL_VOICE ) {
118112 parts . push (
@@ -136,34 +130,44 @@ client.on(GatewayDispatchEvents.MessageCreate, async ({ data: message }) => {
136130 "- Show your code!" ,
137131 ) ;
138132
139- await client . api . channels . createMessage ( message . channel_id , {
140- flags : MessageFlags . IsComponentsV2 ,
133+ return {
134+ type : ComponentType . Container ,
141135 components : [
142136 {
143- type : ComponentType . Container ,
137+ type : ComponentType . TextDisplay ,
138+ content : parts . join ( "\n" ) ,
139+ } ,
140+ {
141+ type : ComponentType . Section ,
144142 components : [
145143 {
146144 type : ComponentType . TextDisplay ,
147- content : parts . join ( "\n" ) ,
148- } ,
149- {
150- type : ComponentType . Section ,
151- components : [
152- {
153- type : ComponentType . TextDisplay ,
154- content : "Issue solved? Press the button!" ,
155- } ,
156- ] ,
157- accessory : {
158- type : ComponentType . Button ,
159- custom_id : "solved" ,
160- style : ButtonStyle . Success ,
161- label : "Solved" ,
162- } ,
145+ content : lock ? "Issue was marked as resolved." : "Issue solved? Press the button!" ,
163146 } ,
164147 ] ,
148+ accessory : {
149+ type : ComponentType . Button ,
150+ custom_id : "solved" ,
151+ style : lock ? ButtonStyle . Secondary : ButtonStyle . Success ,
152+ label : "Solved" ,
153+ disabled : lock ,
154+ } ,
165155 } ,
166156 ] ,
157+ } as APIContainerComponent ;
158+ }
159+
160+ client . on ( GatewayDispatchEvents . MessageCreate , async ( { data : message } ) => {
161+ const parent = supportThreadParents . get ( message . channel_id ) ;
162+ if ( message . id !== message . channel_id || ! parent || ! ASSISTCHANNELS . includes ( parent ) ) {
163+ return ;
164+ }
165+
166+ supportThreadParents . delete ( message . channel_id ) ;
167+
168+ await client . api . channels . createMessage ( message . channel_id , {
169+ flags : MessageFlags . IsComponentsV2 ,
170+ components : [ getComponent ( parent ) ] ,
167171 } ) ;
168172} ) ;
169173
@@ -196,7 +200,9 @@ client.on(GatewayDispatchEvents.InteractionCreate, async ({ data: interaction })
196200 content : message ,
197201 } ) ;
198202
199- await client . api . interactions . updateMessage ( interaction . id , interaction . token , { } ) ;
203+ await client . api . interactions . updateMessage ( interaction . id , interaction . token , {
204+ components : [ getComponent ( interaction . channel . parent_id , true ) ] ,
205+ } ) ;
200206 await client . rest . patch ( Routes . channel ( interaction . channel . id ) , {
201207 body : {
202208 archived : true ,
0 commit comments