From fe3a92a76edad427595bd73287595991fb1367f2 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sat, 11 Apr 2020 11:29:40 -0400 Subject: [PATCH] Fix --- commands/edit-text/mocking.js | 2 +- commands/edit-text/say.js | 2 +- commands/edit-text/webhook.js | 2 +- commands/info/first-message.js | 2 +- commands/info/user.js | 2 +- commands/other/cleverbot.js | 2 +- commands/other/phone-book.js | 2 +- commands/other/phone.js | 4 ++-- commands/other/portal-send.js | 6 +++--- commands/util/help.js | 3 ++- commands/util/unknown-command.js | 4 ++-- structures/commands/AutoReply.js | 2 +- structures/commands/Subreddit.js | 2 +- 13 files changed, 18 insertions(+), 17 deletions(-) diff --git a/commands/edit-text/mocking.js b/commands/edit-text/mocking.js index 11649aa2..398f686d 100644 --- a/commands/edit-text/mocking.js +++ b/commands/edit-text/mocking.js @@ -22,7 +22,7 @@ module.exports = class MockingCommand extends Command { } run(msg, { text }) { - const canEmoji = msg.channel.type === 'text' + const canEmoji = msg.guild ? msg.channel.permissionsFor(this.client.user).has('USE_EXTERNAL_EMOJIS') : true; const letters = text.split(''); diff --git a/commands/edit-text/say.js b/commands/edit-text/say.js index 332d8863..78e01e54 100644 --- a/commands/edit-text/say.js +++ b/commands/edit-text/say.js @@ -20,7 +20,7 @@ module.exports = class SayCommand extends Command { async run(msg, { text }) { try { - if (msg.channel.type === 'text' && msg.deletable) await msg.delete(); + if (msg.guild && msg.deletable) await msg.delete(); return msg.say(text); } catch { return msg.say(text); diff --git a/commands/edit-text/webhook.js b/commands/edit-text/webhook.js index bcc9b1a9..3e96375c 100644 --- a/commands/edit-text/webhook.js +++ b/commands/edit-text/webhook.js @@ -23,7 +23,7 @@ module.exports = class WebhookCommand extends Command { async run(msg, { content }) { try { - if (msg.channel.type === 'text' && msg.deletable) await msg.delete(); + if (msg.guild && msg.deletable) await msg.delete(); await this.client.webhook.send(content); return null; } catch (err) { diff --git a/commands/info/first-message.js b/commands/info/first-message.js index a8bd0410..2bd7b35c 100644 --- a/commands/info/first-message.js +++ b/commands/info/first-message.js @@ -22,7 +22,7 @@ module.exports = class FirstMessageCommand extends Command { } async run(msg, { channel }) { - if (channel.type === 'text' && !channel.permissionsFor(this.client.user).has('READ_MESSAGE_HISTORY')) { + if (msg.guild && !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 }); diff --git a/commands/info/user.js b/commands/info/user.js index 90e7753e..34a9edc3 100644 --- a/commands/info/user.js +++ b/commands/info/user.js @@ -34,7 +34,7 @@ module.exports = class UserCommand extends Command { • Discord Join Date: ${moment.utc(user.createdAt).format('MM/DD/YYYY h:mm A')} • ${user.bot ? 'Bot' : 'Not a Bot'} `; - if (msg.channel.type === 'text') { + if (msg.guild) { try { const member = await msg.guild.members.fetch(user.id); const defaultRole = msg.guild.roles.cache.get(msg.guild.id); diff --git a/commands/other/cleverbot.js b/commands/other/cleverbot.js index d73f0416..c5394612 100644 --- a/commands/other/cleverbot.js +++ b/commands/other/cleverbot.js @@ -36,7 +36,7 @@ module.exports = class CleverbotCommand extends Command { async run(msg, { text }, fromPattern) { if (fromPattern) { - if (this.client.botListGuilds.includes(msg.guild.id)) return null; + if (msg.guild && this.client.botListGuilds.includes(msg.guild.id)) return null; text = msg.patternMatches[2]; } try { diff --git a/commands/other/phone-book.js b/commands/other/phone-book.js index a3dce11a..b9ee4502 100644 --- a/commands/other/phone-book.js +++ b/commands/other/phone-book.js @@ -22,7 +22,7 @@ module.exports = class PhoneBookCommand extends Command { run(msg, { query }) { const channels = this.client.channels.cache.filter(channel => { const search = query.toLowerCase(); - return channel.type === 'text' + return channel.guild && channel.topic && channel.topic.includes('') && !channel.topic.includes('') diff --git a/commands/other/phone.js b/commands/other/phone.js index 0b2a3e9c..102db151 100644 --- a/commands/other/phone.js +++ b/commands/other/phone.js @@ -45,7 +45,7 @@ module.exports = class PhoneCommand extends Command { if (channelID !== 'count' && inCall) { return msg.say('This channel is already in a phone call.'); } - const channels = this.client.channels.cache.filter(channel => channel.type === 'text' + const channels = this.client.channels.cache.filter(channel => channel.guild && channel.topic && channel.topic.includes('') && !msg.guild.channels.cache.has(channel.id)); @@ -54,7 +54,7 @@ module.exports = class PhoneCommand extends Command { if (channelID) { if (channelID === 'count') return msg.say(`☎️ **${channels.size}** currently open lines.`); channel = this.client.channels.cache.get(channelID); - if (!channel || channel.type !== 'text') return msg.reply('This channel does not exist.'); + if (!channel || !channel.guild) return msg.reply('This channel does not exist.'); if (!channel.topic || !channel.topic.includes('')) { return msg.reply('This channel does not allow phone calls.'); } diff --git a/commands/other/portal-send.js b/commands/other/portal-send.js index a21e45d3..100d4cef 100644 --- a/commands/other/portal-send.js +++ b/commands/other/portal-send.js @@ -27,9 +27,9 @@ module.exports = class PortalSendCommand extends Command { async run(msg, { message }) { if (/discord(\.gg|app\.com\/invite|\.me)\//gi.test(message)) return msg.reply('Please do not send invites.'); let channels = this.client.channels.cache.filter( - channel => channel.type === 'text' && channel.topic && channel.topic.includes('') + channel => channel.guild && channel.topic && channel.topic.includes('') ); - if (msg.channel.type === 'text') { + if (channel.guild) { channels = channels.filter(channel => !msg.guild.channels.cache.has(channel.id)); } if (message.toLowerCase() === 'count') { @@ -38,7 +38,7 @@ module.exports = class PortalSendCommand extends Command { if (!channels.size) return msg.reply('No channels have an open portal...'); const channel = channels.random(); try { - const displayName = msg.channel.type === 'text' ? msg.guild.name : 'DM'; + const displayName = msg.guild ? msg.guild.name : 'DM'; await channel.send(`**${this.portalEmoji} ${msg.author.tag} (${displayName}):** ${message}`); return msg.say(`Message sent to **${channel.name}** in **${channel.guild.name}**!`); } catch { diff --git a/commands/util/help.js b/commands/util/help.js index bfada2b4..08f14645 100644 --- a/commands/util/help.js +++ b/commands/util/help.js @@ -34,7 +34,8 @@ module.exports = class HelpCommand extends Command { const commands = group.commands.filter(cmd => { if (owner) return true; if (cmd.ownerOnly || cmd.hidden) return false; - if (this.client.botListGuilds.includes(msg.guild.id) && cmd instanceof AutoReplyCommand) { + const inBotList = msg.guild && this.client.botListGuilds.includes(msg.guild.id); + if (inBotList && cmd instanceof AutoReplyCommand) { return false; } return true; diff --git a/commands/util/unknown-command.js b/commands/util/unknown-command.js index 321dcea8..08cad8d8 100644 --- a/commands/util/unknown-command.js +++ b/commands/util/unknown-command.js @@ -16,8 +16,8 @@ module.exports = class UnknownCommandCommand extends Command { } run(msg) { - if (msg.channel.type !== 'text') return null; - if (this.client.botListGuilds.includes(msg.guild.id)) return null; + if (!msg.guild) return null; + if (msg.guild && this.client.botListGuilds.includes(msg.guild.id)) return null; const commands = this.makeCommandArray(this.client.isOwner(msg.author), msg.channel.nsfw); const command = msg.content.match(this.client.dispatcher._commandPatterns[this.client.commandPrefix]); const str = command ? command[2] : msg.content.split(' ')[0]; diff --git a/structures/commands/AutoReply.js b/structures/commands/AutoReply.js index 752d04c1..a9daa31e 100644 --- a/structures/commands/AutoReply.js +++ b/structures/commands/AutoReply.js @@ -8,7 +8,7 @@ module.exports = class AutoReplyCommand extends Command { } run(msg, args, fromPattern) { - if (this.client.botListGuilds.includes(msg.guild.id)) return null; + if (msg.guild && this.client.botListGuilds.includes(msg.guild.id)) return null; return this.reply ? msg.reply(this.generateText(fromPattern)) : msg.say(this.generateText(fromPattern)); } diff --git a/structures/commands/Subreddit.js b/structures/commands/Subreddit.js index e10ca4d1..0d18a054 100644 --- a/structures/commands/Subreddit.js +++ b/structures/commands/Subreddit.js @@ -18,7 +18,7 @@ module.exports = class SubredditCommand extends Command { async run(msg, { subreddit }, fromPattern) { if (fromPattern) { - if (this.client.botListGuilds.includes(msg.guild.id)) return null; + if (msg.guild && this.client.botListGuilds.includes(msg.guild.id)) return null; subreddit = msg.patternMatches[1]; } if (!subreddit) subreddit = typeof this.subreddit === 'function' ? this.subreddit() : this.subreddit;