Send image as attachment when the message is only a link

This commit is contained in:
Supositware 2019-03-15 17:08:16 +01:00
parent be34506063
commit 79b9763159

View file

@ -1,6 +1,7 @@
const { Listener } = require('discord-akairo');
const { MessageEmbed } = require('discord.js');
const reload = require('auto-reload');
const getUrls = require('get-urls');
let messageID = require('../../json/starboard.json');
class MessageReactionAddListener extends Listener {
@ -14,6 +15,7 @@ class MessageReactionAddListener extends Listener {
async exec(reaction) {
let messageContent = reaction.message.content;
let messageAttachments = reaction.message.attachments.map(u=> `${u.url}`);
let URL = [...getUrls(messageContent)];
let starboardChannel;
let staremote;
@ -49,6 +51,11 @@ class MessageReactionAddListener extends Listener {
.setAuthor(reaction.message.author.username, reaction.message.author.displayAvatarURL())
.setTimestamp();
if (URL) {
return channel.send(`in: ${reaction.message.channel}\nhttps://discordapp.com/channels/${reaction.message.guild.id}/${reaction.message.channel.id}/${reaction.message.id}`, {files: [URL[0]]})
.catch(() => channel.send(`${reaction.message.author.username}, in: ${reaction.message.channel}\n${URL[0]}`));
}
return channel.send(`in: ${reaction.message.channel}`, {files: messageAttachments, embed: starEmbed})
.catch(() => channel.send(`${reaction.message.author.username}, in: ${reaction.message.channel}`, { embed: starEmbed}));
}
@ -87,6 +94,11 @@ class MessageReactionAddListener extends Listener {
.setAuthor(reaction.message.author.username, reaction.message.author.displayAvatarURL())
.setTimestamp();
if (URL) {
return channel.send(`in: ${reaction.message.channel}\nhttps://discordapp.com/channels/${reaction.message.guild.id}/${reaction.message.channel.id}/${reaction.message.id}`, {files: [URL[0]]})
.catch(() => channel.send(`${reaction.message.author.username}, in: ${reaction.message.channel}\n${URL[0]}`));
}
return channel.send(`in: ${reaction.message.channel}`,{files: messageAttachments, embed: shameEmbed})
.catch(() => channel.send(`${reaction.message.author.username}, in: ${reaction.message.channel}`, { embed: shameEmbed}));
}