1- import { Message } from "discord.js" ;
1+ import type { Message } from "discord.js" ;
22import { Command } from "discord-akairo" ;
3- import fetch from "node-fetch" ;
4- import { stringify } from "querystring" ;
5-
3+ import Doc from "discord.js-docs" ;
64export default class DiscordCommand extends Command {
75 public constructor ( ) {
86 super ( "djs-docs" , {
97 aliases : [ "djs" , "d.js" , "djsdocs" , "discordjs" , "discord.js" ] ,
108 description : {
11- content : "Searches discord.js documentation for what it thinks you mean. Defaults to using the master branch" ,
9+ content : "Searches discord.js documentation for what it thinks you mean. Defaults to using the main branch" ,
1210 usage : "<query> <optional branch>" ,
13- examples : [ "Guild#Members" , "Guild#Members master " ] ,
11+ examples : [ "Guild#Members" , "Guild#Members main " ] ,
1412 } ,
1513 channel : "guild" ,
1614 clientPermissions : [ "EMBED_LINKS" ] ,
@@ -27,7 +25,7 @@ export default class DiscordCommand extends Command {
2725 } ,
2826 {
2927 id : "branch" ,
30- flag : [ "master " , "stable" ] ,
28+ flag : [ "main " , "stable" ] ,
3129 match : "flag" ,
3230 default : "stable" ,
3331 } ,
@@ -38,12 +36,13 @@ export default class DiscordCommand extends Command {
3836 public async exec ( message : Message , { query, branch } : { query : string ; branch : string } ) : Promise < Message | Message [ ] > {
3937 const str = query . split ( " " ) ;
4038
41- const source = branch ? "stable" : "master" ;
42-
43- //src and q being the params accepted by the API
44- const queryString = stringify ( { src : source , q : str . join ( " " ) } ) ;
45- const res = await fetch ( `https://djsdocs.sorta.moe/v2/embed?${ queryString } ` ) ;
46- const embedObj = await res . json ( ) ;
39+ const source = branch ? "stable" : "main" ;
40+ const doc = await Doc . fetch ( source , { force : true } ) ;
41+ const resultEmbed = doc . resolveEmbed ( str . join ( "#" ) ) ;
42+ if ( ! resultEmbed ) return ;
43+ // For typings of djs' embeds
44+ const timeStampDate = new Date ( resultEmbed . timestamp ) ;
45+ const embedObj = { ...resultEmbed , timestamp : timeStampDate } ;
4746
4847 if ( ! embedObj ) return ;
4948
0 commit comments