@@ -12,10 +12,12 @@ import Discord, {
1212 Events ,
1313 GatewayIntentBits ,
1414 type Interaction ,
15+ Message ,
1516 Partials ,
1617} from "discord.js" ;
1718import CommandHandler from "@/commandHandler" ;
1819import { env } from "@/config/env" ;
20+ import { suppressGitHubUnfurl } from "./util/suppressGitHubUnfurl" ;
1921
2022process . on ( "unhandledRejection" , reason => {
2123 console . log ( "Unhandled Rejection:" , reason ) ;
@@ -24,8 +26,9 @@ process.on("unhandledRejection", reason => {
2426const client = new Discord . Client ( {
2527 intents : [
2628 GatewayIntentBits . Guilds ,
27- GatewayIntentBits . GuildMessages ,
2829 GatewayIntentBits . GuildEmojisAndStickers ,
30+ GatewayIntentBits . GuildMessages ,
31+ GatewayIntentBits . MessageContent ,
2932 ] ,
3033 partials : [ Partials . Message , Partials . Channel , Partials . Reaction ] ,
3134} ) ;
@@ -61,24 +64,15 @@ client.on(Events.InteractionCreate, async (interaction: Interaction) => {
6164client . on ( Events . Error , e => {
6265 console . error ( "Discord client error!" , e ) ;
6366} ) ;
64- client . on ( Events . MessageCreate , async message => {
65- if ( message . author . bot ) return ;
66-
67- message = await message . fetch ( ) ;
6867
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+ } ) ;
7472
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 ) ;
8276} ) ;
8377
8478client . login ( env . DISCORD_TOKEN ) ;
0 commit comments