11import * as Sentry from "@sentry/node" ;
22import colors from "colors" ;
3- import { ActionRowBuilder , ButtonBuilder , ButtonStyle , MessageFlags , WebhookClient } from "discord.js" ;
3+ import {
4+ ActionRowBuilder ,
5+ ButtonBuilder ,
6+ ButtonStyle ,
7+ ContainerBuilder , Interaction ,
8+ MessageFlags , SectionBuilder , SeparatorBuilder , SeparatorSpacingSize ,
9+ TextDisplayBuilder ,
10+ WebhookClient
11+ } from "discord.js" ;
412import { convertToEmojiPng } from "./emojis.js" ;
513import { LoggingAction } from "../enums/loggingTypes.js" ;
614import { Logger } from "../main/logger.js" ;
715import { Config } from "../main/config.js" ;
816
917colors . enable ( ) ;
1018
11- export async function errorHandler ( interaction : any , client : any , error : Error ) {
19+ export async function errorHandler ( interaction : Interaction , client : any , error : Error ) {
1220 Logger ?. error ( {
1321 timestamp : new Date ( ) . toISOString ( ) ,
1422 level : "error" ,
@@ -25,18 +33,48 @@ export async function errorHandler(interaction: any, client: any, error: Error)
2533
2634
2735 await interaction . editReply ( {
28- content : `## ${ await convertToEmojiPng ( "error" , client . user ?. id ) } An error occurred while processing your interaction.\n-# You can click the button below to report this issue to the developers.` ,
2936 components : [
30- new ActionRowBuilder < ButtonBuilder > ( ) . addComponents (
31- new ButtonBuilder ( )
32- . setCustomId ( "report-error" )
33- . setStyle ( ButtonStyle . Danger )
34- . setLabel ( "Report Error" )
35- . setEmoji ( "<:error:1366426689961459893>" )
36- ) ,
37+ new ContainerBuilder ( )
38+ . addSectionComponents (
39+ new SectionBuilder ( )
40+ . addTextDisplayComponents (
41+ new TextDisplayBuilder ( )
42+ . setContent ( [
43+ `## ${ await convertToEmojiPng ( "error" , client . user ?. id ) } An error occurred while processing your interaction.` ,
44+ `-# You can click the button below to report this issue to the developers.`
45+ ] . join ( "\n" ) )
46+ )
47+ . setButtonAccessory ( new ButtonBuilder ( )
48+ . setCustomId ( "report-error" )
49+ . setStyle ( ButtonStyle . Danger )
50+ . setLabel ( "Report Error" )
51+ . setEmoji ( "<:error:1366426689961459893>" ) )
52+ )
53+ . addSeparatorComponents ( new SeparatorBuilder ( ) . setSpacing ( SeparatorSpacingSize . Large ) )
54+ . addSectionComponents (
55+ new SectionBuilder ( )
56+ . addTextDisplayComponents (
57+ new TextDisplayBuilder ( )
58+ . setContent ( [
59+ `> ### ${ await convertToEmojiPng ( "info" , client . user ?. id ) } What will happen if you do it.` ,
60+ `> -# You will share you public user ID` ,
61+ `> -# You will send an Error stack trace` ,
62+ `> -# You will Interaction Related data` ,
63+ `> -# \"Public Database Id's\" like uuids of you setup and or a not sensitive ID` ,
64+ `> -# You will send a contact for the devs to contact you!` ,
65+ ] . join ( "\n" ) )
66+ )
67+ . setButtonAccessory ( new ButtonBuilder ( )
68+ . setStyle ( ButtonStyle . Link )
69+ . setURL ( "https://doc.xyzhub.link/s/disbot/doc/troubleshooting-8PWsSMRNvH" )
70+ . setLabel ( "Read More" )
71+ . setEmoji ( "<:link:1321941111090057248>" ) )
72+ )
73+
74+
3775 ] ,
38- flags : MessageFlags . Ephemeral ,
39- } ) ;
76+ flags : MessageFlags . IsComponentsV2 ,
77+ } )
4078
4179 const collector = interaction . channel ?. createMessageComponentCollector ( {
4280 filter : ( i : {
@@ -47,7 +85,7 @@ export async function errorHandler(interaction: any, client: any, error: Error)
4785 } ) ;
4886
4987 collector ?. on ( "collect" , async ( i : { deferUpdate : ( ) => any ; } ) => {
50- await i . deferUpdate ( ) ;
88+ await i . deferUpdate ( )
5189
5290 let interactionName = "Unknown" ;
5391 if ( interaction . isCommand ( ) || interaction . isContextMenuCommand ( ) ) {
@@ -66,47 +104,63 @@ export async function errorHandler(interaction: any, client: any, error: Error)
66104
67105 if ( ! client . user ) throw new Error ( "Client user is not defined" ) ;
68106 await webHookClient . send ( {
69- content : `-# <:error:1366430438444236911> **Bug Report Submitted**` ,
70- embeds : [
71- {
72- author : {
73- name : `${ interaction . user . tag } (${ interaction . user . id } )` ,
74- icon_url : interaction . user . displayAvatarURL ( ) ,
75- } ,
76- color : 0x2B2D31 ,
77- description : [
78- `<:error:1366430438444236911> **Error Report**` ,
79- `> **User:** ***\`${ interaction . user . username } \`*** (\`${ interaction . user . id } \`)` ,
80- `> **Error:** \`${ error . name } \`` ,
81- `> - \`${ error . message } \`` ,
82- `> **Interaction Type:** \`${ interaction . type == 2 ? "Application Command" : interaction . type == 4 ? "ApplicationCommandAutocomplete" : interaction . type == 3 ? "Message Component" : interaction . type == 5 ? "Modal Submit" : interaction . type == 1 ? "Ping" : "Unknown" } \`` ,
83- `> **Interaction Name/ID:** \`${ interactionName } \`` ,
84- ] . join ( "\n" ) ,
85- timestamp : new Date ( ) . toISOString ( ) ,
86- } ,
87- {
88- author : {
89- name : `${ client . user . tag } (${ client . user . id } )` ,
90- icon_url : client . user . displayAvatarURL ( ) ,
91- } ,
92- color : 0x2B2D31 ,
93- description : [
94- `||\`\`\`ts\n${ error . stack } \n\`\`\`||` ,
95- ] . join ( "\n" ) ,
96- timestamp : new Date ( ) . toISOString ( ) ,
97- } ,
107+ withComponents : true ,
108+ flags : MessageFlags . IsComponentsV2 ,
109+ components : [
110+ new ContainerBuilder ( )
111+ . addTextDisplayComponents (
112+ new TextDisplayBuilder ( )
113+ . setContent (
114+ [
115+ `<:error:1366430438444236911> **Error Report**` ,
116+ `> **User:** ***\`${ interaction . user . username } \`*** (\`${ interaction . user . id } \`)` ,
117+ `> **Error:** \`${ error . name } \`` ,
118+ `> - \`${ error . message } \`` ,
119+ `> **Interaction Id**: \`${ interaction . id } \`` ,
120+ `> **Interaction Type:** \`${ interaction . type == 2 ? "Application Command" : interaction . type == 3 ? "Message Component" : interaction . type == 5 ? "Modal Submit" : "Unknown" } \`` ,
121+ `> **Interaction Name/ID:** \`${ interactionName } \`` ,
122+ `> **Timestamp**: <t:${ Math . floor ( new Date ( ) . getTime ( ) / 1000 ) } :F>`
123+ ] . join ( "\n" )
124+ )
125+ ) ,
126+ new TextDisplayBuilder ( )
127+ . setContent ( [
128+ `||\`\`\`ts\n${ error . stack } \n\`\`\`||`
129+ ] . join ( "\n" ) )
98130 ] ,
99- allowedMentions : { parse : [ ] } ,
131+ allowedMentions : {
132+ parse : [ ]
133+ } ,
100134 username : "DisBot Bug Reporter" ,
101- avatarURL : client . user ?. displayAvatarURL ( ) ,
102- appliedTags : [ "1366430372484878537" , "1366430599811694622" ] ,
103- threadName : `Bug Report - ${ interaction . user . tag } (${ interaction . user . id } ) - Interaction` ,
104- } ) ;
135+ avatarURL :
136+ client . user ?. displayAvatarURL ( ) ,
137+ appliedTags :
138+ [ "1366430372484878537" , "1366430599811694622" ] ,
139+ threadName :
140+ `Bug Report - ${ interaction . user . tag } (${ interaction . user . id } ) - Interaction` ,
141+ } )
142+ ;
105143
106144 await interaction . editReply ( {
107- content : `## ${ await convertToEmojiPng ( "check" , client . user ?. id ) } Your error report has been sent to the developers. Thank you for your help!` ,
108- components : [ ] ,
109- embeds : [ ] ,
145+ components : [
146+ new ContainerBuilder ( )
147+ . addSectionComponents (
148+ new SectionBuilder ( )
149+ . addTextDisplayComponents (
150+ new TextDisplayBuilder ( )
151+ . setContent ( [
152+ `## ${ await convertToEmojiPng ( "check" , client . user ?. id ) } Successfully sent your Error Report to the Discord!` ,
153+ ] . join ( "\n" ) )
154+ )
155+ . setButtonAccessory ( new ButtonBuilder ( )
156+ . setStyle ( ButtonStyle . Link )
157+ . setURL ( "https://disbot.app/discord" )
158+ . setLabel ( "Join our Discord" )
159+ . setEmoji ( "<:discord_cube:1325896195083604080>" ) )
160+ )
161+
162+ ] ,
163+ flags : MessageFlags . IsComponentsV2 ,
110164 } ) ;
111165 } ) ;
112166 }
0 commit comments