Files
xiao/commands/search/soundcloud.js
T
Daniel Odendahl Jr 319df9c0d3 Re-Add Logos
2017-05-12 21:20:18 +00:00

55 lines
2.1 KiB
JavaScript

const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js');
const request = require('superagent');
const { SOUNDCLOUD_KEY } = process.env;
module.exports = class SoundCloudCommand extends Command {
constructor(client) {
super(client, {
name: 'soundcloud',
group: 'search',
memberName: 'soundcloud',
description: 'Searches SoundCloud for a song.',
args: [
{
key: 'query',
prompt: 'What do you want to search SoundCloud for?',
type: 'string',
parse: text => encodeURIComponent(text)
}
]
});
}
async run(msg, args) {
if (msg.channel.type !== 'dm')
if (!msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS'))
return msg.say('This Command requires the `Embed Links` Permission.');
const { query } = args;
try {
const { body } = await request
.get(`https://api.soundcloud.com/tracks?q=${query}&client_id=${SOUNDCLOUD_KEY}`);
if (!body.length) throw new Error('No Results.');
const embed = new RichEmbed()
.setColor(0xF15A22)
.setAuthor('SoundCloud', 'https://i.imgur.com/lFIz7RU.png')
.setTitle(body[0].title)
.setURL(body[0].permalink_url)
.setThumbnail(body[0].artwork_url)
.addField('**Artist:**',
body[0].user.username)
.addField('**Download Count:**',
body[0].download_count, true)
.addField('**Comment Count**',
body[0].comment_count, true)
.addField('**Playback Count:**',
body[0].playback_count, true)
.addField('**Favorited Count:**',
body[0].favoritings_count, true);
return msg.embed(embed);
} catch (err) {
return msg.say(err);
}
}
};