community-relations/src/commands/djs.ts

38 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-05-16 19:39:11 -04:00
import { Message, EmbedOptions } from 'eris';
import axios, { AxiosResponse } from 'axios';
2020-05-05 08:51:20 -04:00
import { Client, Command, RichEmbed } from '../class';
export default class DJS extends Command {
constructor(client: Client) {
super(client);
this.name = 'djs';
this.description = 'Get information about Discord.js.';
this.usage = 'djs <query>';
this.permissions = 0;
this.guildOnly = false;
this.enabled = true;
}
public async run(message: Message, args: string[]) {
try {
if (!args[0]) return this.client.commands.get('help').run(message, [this.name]);
let res: AxiosResponse<EmbedOptions>;
2020-05-18 23:38:53 -04:00
try {
res = await axios.get(`https://djsdocs.sorta.moe/v2/embed?src=master&q=${args[0]}`);
} catch (err) {
return this.error(message.channel, 'Please try again later, something unexpected happened.');
2020-05-18 23:38:53 -04:00
}
if (!res.data) return this.error(message.channel, 'Could not find information. Try something else.');
2020-05-05 08:51:20 -04:00
const embed = new RichEmbed(res.data);
2020-05-18 23:38:53 -04:00
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setTimestamp();
return message.channel.createMessage({ embed });
2020-05-05 08:51:20 -04:00
} catch (err) {
return this.client.util.handleError(err, message, this);
}
}
}