File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ const { SlashCommandBuilder } = require ( "@discordjs/builders" ) ;
2
+ const cheerio = require ( "cheerio" ) ;
3
+ module . exports = {
4
+ data : new SlashCommandBuilder ( )
5
+ . setName ( "csesoclinks" )
6
+ . setDescription ( "Provides CSESoc Linktree links." ) ,
7
+ async execute ( interaction ) {
8
+ fetch ( "https://linktr.ee/csesoc" )
9
+ . then ( ( res ) => {
10
+ return res . text ( ) ;
11
+ } )
12
+ . then ( ( html ) => {
13
+ const $ = cheerio . load ( html ) ;
14
+ const links = $ ( "a" ) ;
15
+ let output = "" ;
16
+ links . each ( ( index , value ) => {
17
+ const title = $ ( value ) . text ( ) . trim ( ) ;
18
+ const href = $ ( value ) . attr ( "href" ) ;
19
+ if ( href && href !== "#" && ! title . includes ( "Linktree" ) ) {
20
+ output += `${ title } : ${ href } \n` ;
21
+ }
22
+ } ) ;
23
+ interaction . reply ( {
24
+ content : output ,
25
+ } ) ;
26
+ } )
27
+ . catch ( ( err ) => {
28
+ console . log ( "Failed to fetch page: " , err ) ;
29
+ } ) ;
30
+ } ,
31
+ } ;
You can’t perform that action at this time.
0 commit comments