File tree Expand file tree Collapse file tree 4 files changed +24
-26
lines changed
Expand file tree Collapse file tree 4 files changed +24
-26
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { CHANNELS } from "../constants/channels.js";
44import {
55 constructDiscordLink ,
66 fetchReactionMembers ,
7+ getMessage ,
78 isHelpful ,
89 isStaff ,
910} from "../helpers/discord.js" ;
@@ -58,7 +59,14 @@ const autoThread: ChannelHandlers = {
5859 return ;
5960 }
6061
61- const { channel : thread , author, guild } = await reaction . message . fetch ( ) ;
62+ const reactionMsg = await getMessage ( reaction . message ) ;
63+
64+ if ( ! reactionMsg ) {
65+ return ;
66+ }
67+
68+ const { channel : thread , author, guild } = reactionMsg ;
69+
6270 const starter = thread . isThread ( )
6371 ? await thread . fetchStarterMessage ( )
6472 : undefined ;
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import {
1111} from "discord.js" ;
1212import cooldown from "./cooldown.js" ;
1313import type { ChannelHandlers } from "../types/index.d.ts" ;
14- import { isStaff } from "../helpers/discord.js" ;
14+ import { getMessage , isStaff } from "../helpers/discord.js" ;
1515import {
1616 extractSearchKey ,
1717 getReactDocsContent ,
@@ -1359,7 +1359,11 @@ const commands: ChannelHandlers = {
13591359 return ;
13601360 }
13611361
1362- const msg = await maybeMessage . fetch ( ) ;
1362+ const msg = await getMessage ( maybeMessage ) ;
1363+
1364+ if ( ! msg ) {
1365+ return ;
1366+ }
13631367
13641368 commandsList . forEach ( ( command ) => {
13651369 const keyword = command . words . find ( ( word ) => {
Original file line number Diff line number Diff line change @@ -51,6 +51,14 @@ export const isStaffOrHelpful = (member: GuildMember) => {
5151export const constructDiscordLink = ( message : Message | PartialMessage ) =>
5252 `https://discord.com/channels/${ message . guild ?. id } /${ message . channel . id } /${ message . id } ` ;
5353
54+ export const getMessage = async ( message : Pick < Message , "fetch" > ) => {
55+ try {
56+ return await message . fetch ( ) ;
57+ } catch {
58+ return null ;
59+ }
60+ } ;
61+
5462export const fetchReactionMembers = async (
5563 guild : Guild ,
5664 reaction : MessageReaction | PartialMessageReaction ,
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ import { recommendBookCommand } from "./features/book-list.js";
4242import { mdnSearch } from "./features/mdn.js" ;
4343import "./server.js" ;
4444import { jobScanner } from "./features/job-scanner.js" ;
45+ import { getMessage } from "./helpers/discord.js" ;
4546
4647export const bot = new Client ( {
4748 intents : [
@@ -134,29 +135,6 @@ const addHandler = (
134135 } ) ;
135136} ;
136137
137- const getMessage = async ( message : Message ) => {
138- try {
139- return await message . fetch ( ) ;
140- } catch ( e : unknown ) {
141- logger . log (
142- "ERROR" ,
143- `Failed to fetch message: ${ JSON . stringify ( {
144- error : e ,
145- messageId : message . id ,
146- partial : message . partial ,
147- channelId : message . channelId ,
148- content : message . content ,
149- authorUsername : message . author ?. username ,
150- authorSystem : message . author ?. system ,
151- authorBot : message . author ?. bot ,
152- system : message . system ,
153- } ) } `,
154- ) ;
155-
156- return null ;
157- }
158- } ;
159-
160138const handleMessage = async ( message : Message ) => {
161139 if ( message . system ) {
162140 return ;
You can’t perform that action at this time.
0 commit comments