nodbot/commands/gif.js
2021-07-13 20:57:37 -04:00

32 lines
1.2 KiB
JavaScript

const functions = require('../functions');
const giphy = require('giphy-api')(process.env.giphyAPIKey);
module.exports = {
name: 'gif',
description: 'Send a GIF',
execute(message, file) {
const client = message.client;
if (!client.gifs.has(file.name)) {
giphy.search(file.name).then(function (res) {
if (res.data[0] != undefined) {
// message.channel.send(file.name + ' requested by ' + message.author.username + '\n' + res.data[0].embed_url).then().catch(console.error);
const gifInfo = {
'name': file.name,
'embed_url': res.data[0].images.original.url
};
message.channel.send(functions.createGifEmbed(gifInfo, message.author, `${file.name}.${file.extension}`));
} else {
message.channel.send('I was unable to find a gif of ' + file.name);
}
})
.catch(err => console.error(err));
} else {
// message.channel.send(file.name + ' requested by ' + message.author.username + '\n' + client.gifs.get(file.name).embed_url);
const gifInfo = {
'name': file.name,
'embed_url': client.gifs.get(file.name).embed_url
};
message.channel.send(functions.createGifEmbed(gifInfo, message.author, `${file.name}.${file.extension}`));
}
}
}