import type { HelpObj } from '../../structures/commandhandler' ; import { MessageEmbed } from 'discord.js' ; import type ReknownClient from '../../structures/client' ; import fetch from 'node-fetch' ; import { stringify } from 'querystring' ; import type { Message , PermissionString } from 'discord.js' ; export async function run ( client , message , args ) { const q = args [ 1 ] ; let source = args [ 2 ] || 'stable' ; if ( ! q ) return client . functions . noArg ( message , 1 , 'a query to search for.' ) ; source = source . toLowerCase ( ) ; if ( source === '11.5-dev' ) source = `https://raw.githubusercontent.com/discordjs/discord.js/docs/${ source }.json` ; const qstring = stringify ( { q : q , src : source } ) ; const raw = await fetch ( `https://djsdocs.sorta.moe/v2/embed?${ qstring }` ) . then ( res => res . json ( ) ) ; if ( ! raw ) return client . functions . badArg ( message , 1 , 'I did not find anything with that query.' ) ; if ( raw . message === 'Couldn\'t find/parse given source.' ) return client . functions . badArg ( message , 2 , 'The source provided was invalid.' ) ; const embed = new MessageEmbed ( raw ) ; message . channel . send ( { embed : embed } ) ; } export const help = { aliases : [ ] , category : 'Documentation' , desc : 'Displays documentation for Discord.js' , dm : true , togglable : true , usage : 'docs <Query> [Source]' } ; export const memberPerms = [ ] ; export const permissions = [ 'EMBED_LINKS' ] ;