From 89f780ddfb4fa978fdb1be0901822e6ab7b264f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Sat, 9 May 2020 22:01:51 -0400 Subject: [PATCH] used await instead of .then().catch() (KhaaZ) --- src/commands/djs.ts | 52 ++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/commands/djs.ts b/src/commands/djs.ts index 129083e..9060c82 100644 --- a/src/commands/djs.ts +++ b/src/commands/djs.ts @@ -17,35 +17,35 @@ export default class DJS extends Command { try { if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); - return axios.get(`https://djsdocs.sorta.moe/v2/embed?src=master&q=${args[0]}`) - .then((res) => { - const { data } = res; - if (!data) return this.error(message.channel, 'Could not find information. Try something else.'); + let res; + try { + res = await axios.get(`https://djsdocs.sorta.moe/v2/embed?src=master&q=${args[0]}`); + } catch (err) { + this.error(message.channel, 'Please try again later, something unexpected happened.'); + return this.client.util.handleError(err, message, this); + } + const { data } = res; + if (!data) return this.error(message.channel, 'Could not find information. Try something else.'); - const name: string = data.author?.name || ''; - const icon_url: string = data.author?.icon_url || ''; - const author_url: string = data.author?.url || ''; - const description: string = data.description || 'None'; - const title: string = data.title || ''; + const name: string = data.author?.name || ''; + const icon_url: string = data.author?.icon_url || ''; + const author_url: string = data.author?.url || ''; + const description: string = data.description || 'None'; + const title: string = data.title || ''; - const embed = new RichEmbed(); - embed.setAuthor(name, icon_url, author_url); - embed.setColor(0x2296f3); - embed.setTitle(title); - embed.setDescription(description); - if (data.fields !== undefined && data.fields.length > 0) { - data.fields.forEach((field) => { - embed.addField(field.name, field.value); - }); - } - embed.setFooter(this.client.user.username, this.client.user.avatarURL); - embed.setTimestamp(); - return message.channel.createMessage({ embed }); - }) - .catch((err) => { - this.error(message.channel, 'Please try again later, something unexpected happened.'); - this.client.util.handleError(err, message, this); + const embed = new RichEmbed(); + embed.setAuthor(name, icon_url, author_url); + embed.setColor(0x2296f3); + embed.setTitle(title); + embed.setDescription(description); + if (data.fields !== undefined && data.fields.length > 0) { + data.fields.forEach((field) => { + embed.addField(field.name, field.value); }); + } + embed.setFooter(this.client.user.username, this.client.user.avatarURL); + embed.setTimestamp(); + return message.channel.createMessage({ embed }); } catch (err) { return this.client.util.handleError(err, message, this); }