From fd3bd96ae6824969e30f9e28452231ccf4a5c87a Mon Sep 17 00:00:00 2001 From: TheEssem Date: Mon, 13 Jan 2020 10:31:01 -0600 Subject: [PATCH] Added the message content as a parameter to command.run, re-added message to ban --- commands/ban.js | 5 ++--- commands/qrcreate.js | 4 ++-- events/messageCreate.js | 5 +++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/commands/ban.js b/commands/ban.js index c14e06f..c41a4e4 100644 --- a/commands/ban.js +++ b/commands/ban.js @@ -8,9 +8,8 @@ exports.run = async (message) => { try { await message.channel.guild.banMember(member.id, 0, `ban command used by @${message.author.username}#${message.author.discriminator}`); return `Successfully banned ${member.mention}.`; - } catch (error) { - throw error; - //return `${message.author.mention}, I was unable to ban the member. Have you given me permissions?`; + } catch (e) { + return `${message.author.mention}, I was unable to ban the member. Have you given me permissions?`; } } else { return `${message.author.mention}, you need to provide a member to ban!`; diff --git a/commands/qrcreate.js b/commands/qrcreate.js index e394aab..d0b2d27 100644 --- a/commands/qrcreate.js +++ b/commands/qrcreate.js @@ -1,11 +1,11 @@ const qrcode = require("qrcode"); const stream = require("stream"); -exports.run = async (message, args) => { +exports.run = async (message, args, content) => { if (args.length === 0) return `${message.author.mention}, you need to provide some text to generate a QR code!`; message.channel.sendTyping(); const writable = new stream.PassThrough(); - qrcode.toFileStream(writable, args.join(" "), { margin: 1 }); + qrcode.toFileStream(writable, content, { margin: 1 }); const chunks = []; writable.on("data", (chunk) => { chunks.push(chunk); diff --git a/events/messageCreate.js b/events/messageCreate.js index 3dfede2..8c52e24 100644 --- a/events/messageCreate.js +++ b/events/messageCreate.js @@ -39,7 +39,8 @@ module.exports = async (message) => { // separate commands and args const escapedPrefix = misc.regexEscape(prefix); const prefixRegex = new RegExp(`^(${escapedPrefix})`); - const args = message.content.replace(prefixRegex, "").trim().split(/ +/g); + const content = message.content.replace(prefixRegex, "").trim(); + const args = content.split(/ +/g); const command = args.shift().toLowerCase(); // check if command exists @@ -49,7 +50,7 @@ module.exports = async (message) => { // actually run the command logger.log("info", `${message.author.username} (${message.author.id}) ran command ${command}`); try { - const result = await cmd(message, args); + const result = await cmd(message, args, content.replace(command, "").trim()); // we also provide the message content as a parameter for cases where we need more accuracy if (typeof result === "string") { await client.createMessage(message.channel.id, result); }