Check permissions

This commit is contained in:
Dragon Fire
2018-10-27 20:05:27 -04:00
parent e53c44ad02
commit 9b5a72f934
+4 -1
View File
@@ -9,7 +9,7 @@ module.exports = class FirstMessageCommand extends Command {
group: 'info', group: 'info',
memberName: 'first-message', memberName: 'first-message',
description: 'Responds with the first message ever sent to a channel.', description: 'Responds with the first message ever sent to a channel.',
clientPermissions: ['EMBED_LINKS'], clientPermissions: ['EMBED_LINKS', 'READ_MESSAGE_HISTORY'],
args: [ args: [
{ {
key: 'channel', key: 'channel',
@@ -22,6 +22,9 @@ module.exports = class FirstMessageCommand extends Command {
} }
async run(msg, { channel }) { async run(msg, { channel }) {
if (msg.channel.type === 'text' && !msg.channel.permissionsFor(this.client.user).has('READ_MESSAGE_HISTORY')) {
return msg.reply(`Sorry, I don't have permission to read ${channel}...`);
}
const messages = await channel.messages.fetch({ after: 1, limit: 1 }); const messages = await channel.messages.fetch({ after: 1, limit: 1 });
const message = messages.first(); const message = messages.first();
const format = message.author.avatar && message.author.avatar.startsWith('a_') ? 'gif' : 'png'; const format = message.author.avatar && message.author.avatar.startsWith('a_') ? 'gif' : 'png';