@@ -12,10 +12,12 @@ import Discord, {
12
12
Events ,
13
13
GatewayIntentBits ,
14
14
type Interaction ,
15
+ Message ,
15
16
Partials ,
16
17
} from "discord.js" ;
17
18
import CommandHandler from "@/commandHandler" ;
18
19
import { env } from "@/config/env" ;
20
+ import { suppressGitHubUnfurl } from "./util/suppressGitHubUnfurl" ;
19
21
20
22
process . on ( "unhandledRejection" , reason => {
21
23
console . log ( "Unhandled Rejection:" , reason ) ;
@@ -24,8 +26,9 @@ process.on("unhandledRejection", reason => {
24
26
const client = new Discord . Client ( {
25
27
intents : [
26
28
GatewayIntentBits . Guilds ,
27
- GatewayIntentBits . GuildMessages ,
28
29
GatewayIntentBits . GuildEmojisAndStickers ,
30
+ GatewayIntentBits . GuildMessages ,
31
+ GatewayIntentBits . MessageContent ,
29
32
] ,
30
33
partials : [ Partials . Message , Partials . Channel , Partials . Reaction ] ,
31
34
} ) ;
@@ -61,24 +64,15 @@ client.on(Events.InteractionCreate, async (interaction: Interaction) => {
61
64
client . on ( Events . Error , e => {
62
65
console . error ( "Discord client error!" , e ) ;
63
66
} ) ;
64
- client . on ( Events . MessageCreate , async message => {
65
- if ( message . author . bot ) return ;
66
-
67
- message = await message . fetch ( ) ;
68
67
69
- for ( const embed of message . embeds ) {
70
- if ( ! embed . url ) continue ;
71
-
72
- const url = new URL ( embed . url ) ;
73
- if ( url . host !== "github.com" ) continue ;
68
+ // Message updates contain full data. Typings are corrected in a newer discord.js version.
69
+ client . on ( Events . MessageUpdate , async ( _ , newMessage ) => {
70
+ await suppressGitHubUnfurl ( newMessage as Message ) ;
71
+ } ) ;
74
72
75
- const segments = url . pathname . split ( "/" ) ;
76
- const githubUrlType : string | undefined = segments [ 3 ] ;
77
- if ( githubUrlType === "tree" || githubUrlType === "blob" ) {
78
- await message . suppressEmbeds ( ) ;
79
- return ;
80
- }
81
- }
73
+ client . on ( Events . MessageCreate , async ( message : Message < boolean > ) => {
74
+ if ( message . author . bot ) return ;
75
+ await suppressGitHubUnfurl ( message ) ;
82
76
} ) ;
83
77
84
78
client . login ( env . DISCORD_TOKEN ) ;
0 commit comments