@@ -393,8 +393,9 @@ export default class WebhookData {
393393 }
394394
395395 private async _send ( embeds : any [ ] , attempt = 1 ) {
396+ const thread = this . webhook . threadID ;
396397 try {
397- await request ( 'POST' , `/webhooks/${ this . webhook . webhookID } /${ this . webhook . webhookToken } ` , {
398+ await request ( 'POST' , `/webhooks/${ this . webhook . webhookID } /${ this . webhook . webhookToken } ${ thread ? `?thread_id= ${ thread } ` : '' } ` , {
398399 embeds
399400 } ) ;
400401 } catch ( e ) {
@@ -404,7 +405,9 @@ export default class WebhookData {
404405 await Webhook . update (
405406 {
406407 webhookID : null ,
407- webhookToken : null
408+ webhookToken : null ,
409+ threadID : null ,
410+ threadParent : null
408411 } ,
409412 { where : { id : this . webhook . id } }
410413 ) ;
@@ -413,7 +416,36 @@ export default class WebhookData {
413416 await Webhook . update (
414417 {
415418 webhookID : null ,
416- webhookToken : null
419+ webhookToken : null ,
420+ threadID : null ,
421+ threadParent : null
422+ } ,
423+ { where : { id : this . webhook . id } }
424+ ) ;
425+ } else if ( e . code === 10003 ) {
426+ logger . warn ( `Discord webhook points to a lost thread, removing thread setting @ ${ this . webhook . webhookID } :${ this . webhook . id } ` , e ) ;
427+ await Webhook . update (
428+ {
429+ threadID : null ,
430+ active : false
431+ } ,
432+ { where : { id : this . webhook . id } }
433+ ) ;
434+ } else if ( e . code === 160005 ) {
435+ logger . warn ( `Discord webhook points to a locked thread, removing thread setting @ ${ this . webhook . webhookID } :${ this . webhook . id } ` , e ) ;
436+ await Webhook . update (
437+ {
438+ threadID : null ,
439+ active : false
440+ } ,
441+ { where : { id : this . webhook . id } }
442+ ) ;
443+ } else if ( e . code === 220001 ) {
444+ logger . warn ( `Discord webhook tried posting to forum channel with no thread id @ ${ this . webhook . webhookID } :${ this . webhook . id } ` , e ) ;
445+ await Webhook . update (
446+ {
447+ threadID : '0' ,
448+ active : false
417449 } ,
418450 { where : { id : this . webhook . id } }
419451 ) ;
0 commit comments