JaBa/commands/General/quote.js

98 lines
2.3 KiB
JavaScript
Raw Normal View History

const Command = require("../../base/Command"),
2022-01-04 02:18:28 +05:00
Discord = require("discord.js");
class Quote extends Command {
constructor(client) {
super(client, {
name: "quote",
dirname: __dirname,
enabled: true,
guildOnly: true,
aliases: ["q"],
2022-01-04 02:18:28 +05:00
memberPermissions: [],
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
nsfw: false,
ownerOnly: false,
cooldown: 1000
});
}
async run(message, args, data) {
function embed(m) {
const embed = new Discord.MessageEmbed()
.setAuthor({
name: m.author.tag,
iconURL: m.author.displayAvatarURL({
size: 512,
dynamic: true,
format: "png"
})
})
2022-01-04 02:18:28 +05:00
.setDescription(m.content)
.setColor(m.member ? m.member.roles.highest ? m.member.roles.highest.color : data.config.embed.color : data.config.embed.color)
.setFooter({
text: m.guild.name + " | #" + m.channel.name
})
2022-01-04 02:18:28 +05:00
.setTimestamp(m.createdTimestamp);
if (m.attachments.size > 0) embed.setImage(m.attachments.first().url);
return embed;
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
const msgID = args[0];
if (isNaN(msgID)) {
message.author.send({
content: message.translate("general/quote:MISSING_ID")
}).then(() => {
2022-01-04 02:18:28 +05:00
message.delete();
}).catch(() => {
message.error("misc:CANNOT_DM");
});
return;
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
let channel = args[1];
if (args[1]) {
channel = this.client.channels.cache.get(args[1]);
if (!channel) {
message.author.send(message.translate("general/quote:NO_MESSAGE_ID")).then(() => {
message.delete();
}).catch(() => {
2022-01-13 00:26:23 +05:00
message.error("misc:CANNOT_DM");
2022-01-04 02:18:28 +05:00
});
return;
2022-01-13 00:26:23 +05:00
}
}
2022-01-04 02:18:28 +05:00
if (!channel) {
message.channel.messages.fetch(msgID).catch(() => {
message.author.send((message.translate("general/quote:NO_MESSAGE_ID"))).then(() => {
message.delete();
}).catch(() => {
2022-01-13 00:26:23 +05:00
message.error("misc:CANNOT_DM");
2022-01-04 02:18:28 +05:00
});
return;
}).then((msg) => {
message.delete();
message.reply({
embeds: [embed(msg)]
});
2022-01-04 02:18:28 +05:00
});
} else {
channel.messages.fetch(msgID).catch(() => {
message.author.send(message.translate("general/quote:NO_MESSAGE_ID")).then(() => {
message.delete();
}).catch(() => {
2022-01-13 00:26:23 +05:00
message.error("misc:CANNOT_DM");
2022-01-04 02:18:28 +05:00
});
return;
}).then((msg) => {
message.delete();
message.reply({
embeds: [embed(msg)]
});
2022-01-04 02:18:28 +05:00
});
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
}
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
module.exports = Quote;