1
+ require ( 'dotenv' ) . config ( ) ;
2
+ const { Client, MessageEmbed } = require ( 'discord.js' ) ;
3
+ const client = new Client ( { partials : [ 'MESSAGE' , 'REACTION' ] } ) ;
4
+ client . login ( process . env . BOT_TOKEN ) ;
5
+
6
+ client . on ( 'ready' , ( ) => {
7
+ console . log ( `${ client . user . tag } has logged in.` ) ;
8
+ } ) ;
9
+
10
+ client . on ( 'messageReactionAdd' , async ( reaction , user ) => {
11
+ const handleStarboard = async ( ) => {
12
+ const starboard = client . channels . cache . find ( channel => channel . name . toLowerCase ( ) === 'starboard' ) ;
13
+ const msgs = await starboard . messages . fetch ( { limit : 100 } ) ;
14
+ const existingMsg = msgs . find ( msg =>
15
+ msg . embeds . length === 1 ?
16
+ ( msg . embeds [ 0 ] . footer . text . startsWith ( reaction . message . id ) ? true : false ) : false ) ;
17
+ if ( existingMsg ) existingMsg . edit ( `${ reaction . count } - 🌟` ) ;
18
+ else {
19
+ const embed = new MessageEmbed ( )
20
+ . setAuthor ( reaction . message . author . tag , reaction . message . author . displayAvatarURL ( ) )
21
+ . addField ( 'Url' , reaction . message . url )
22
+ . setDescription ( reaction . message . content )
23
+ . setFooter ( reaction . message . id + ' - ' + new Date ( reaction . message . createdTimestamp ) ) ;
24
+ if ( starboard )
25
+ starboard . send ( '1 - 🌟' , embed ) ;
26
+ }
27
+ }
28
+ if ( reaction . emoji . name === '🌟' ) {
29
+ if ( reaction . message . channel . name . toLowerCase ( ) === 'starboard' ) return ;
30
+ if ( reaction . message . partial ) {
31
+ await reaction . fetch ( ) ;
32
+ await reaction . message . fetch ( ) ;
33
+ handleStarboard ( ) ;
34
+ }
35
+ else
36
+ handleStarboard ( ) ;
37
+ }
38
+ } ) ;
39
+
40
+ client . on ( 'messageReactionRemove' , async ( reaction , user ) => {
41
+ const handleStarboard = async ( ) => {
42
+ const starboard = client . channels . cache . find ( channel => channel . name . toLowerCase ( ) === 'starboard' ) ;
43
+ const msgs = await starboard . messages . fetch ( { limit : 100 } ) ;
44
+ const existingMsg = msgs . find ( msg =>
45
+ msg . embeds . length === 1 ?
46
+ ( msg . embeds [ 0 ] . footer . text . startsWith ( reaction . message . id ) ? true : false ) : false ) ;
47
+ if ( existingMsg ) {
48
+ if ( reaction . count === 0 )
49
+ existingMsg . delete ( { timeout : 2500 } ) ;
50
+ else
51
+ existingMsg . edit ( `${ reaction . count } - 🌟` )
52
+ } ;
53
+ }
54
+ if ( reaction . emoji . name === '🌟' ) {
55
+ if ( reaction . message . channel . name . toLowerCase ( ) === 'starboard' ) return ;
56
+ if ( reaction . message . partial ) {
57
+ await reaction . fetch ( ) ;
58
+ await reaction . message . fetch ( ) ;
59
+ handleStarboard ( ) ;
60
+ }
61
+ else
62
+ handleStarboard ( ) ;
63
+ }
64
+ } ) ;
0 commit comments