From 1c6adc3af4e6edf829d5ac406b847a655a26ac6f Mon Sep 17 00:00:00 2001 From: Frederick Katsura Date: Tue, 20 Jul 2021 21:30:47 -0300 Subject: [PATCH] Patched Issue With defaultChannel Fixed an error where Margarine tried to read the client user when client is undefined in defaultChannel function. --- assets/settingsExample.json | 34 +++++++++++++++--------------- events/guildCreate.js | 42 ++++++++++++++++++++----------------- package-lock.json | 2 +- package.json | 2 +- utilities/utilExport.js | 12 +++++++---- 5 files changed, 50 insertions(+), 42 deletions(-) diff --git a/assets/settingsExample.json b/assets/settingsExample.json index ae3e322..d68d15c 100644 --- a/assets/settingsExample.json +++ b/assets/settingsExample.json @@ -1,19 +1,19 @@ { - "token": "Token Key", - "prefix": "Prefix", - "build": { - "version": "Release 1.6.0", - "releaseDate": "April 27th, 2021" - }, - "database": "./assets/MargarineData.sqlite", - "dateOptions": { - "lang": "en-CA", - "display": { - "year": "numeric", - "month": "long", - "day": "numeric", - "hour": "numeric", - "minute": "numeric" - } - } + "token": "Token Key", + "prefix": "Prefix", + "build": { + "version": "Release 1.6.2", + "releaseDate": "July 20th, 2021" + }, + "database": "./assets/MargarineData.sqlite", + "dateOptions": { + "lang": "en-CA", + "display": { + "year": "numeric", + "month": "long", + "day": "numeric", + "hour": "numeric", + "minute": "numeric" + } + } } diff --git a/events/guildCreate.js b/events/guildCreate.js index f0c8cac..7647c0c 100644 --- a/events/guildCreate.js +++ b/events/guildCreate.js @@ -2,25 +2,29 @@ const { Event } = require("klasa"); const { MessageEmbed } = require("discord.js"); module.exports = class extends Event { - constructor(...args) { - super(...args, { - enabled: true, - event: "guildCreate" - }); - } + constructor(...args) { + super(...args, { + enabled: true, + event: "guildCreate" + }); + } - async run(guild) { - if (!guild.available) { return; } + async run(guild) { + if (!guild.available) { + return; + } - const embed = new MessageEmbed() - .setTimestamp() - .setColor(0xF1C40F) - .setTitle(`Greetings to the users of ${guild.name}!`) - .setDescription(`My name is ${this.client.user.username} and I'd like to thank you for inviting me. I am a helpful and fantastic bot created with Klasa, a discord.js framework.\n - If you want so see my awesome commands, feel free to do ${guild.settings.get("prefix")}help. I will send you my help menu where you will be provided with more information.\n + const embed = new MessageEmbed() + .setTimestamp() + .setColor(0xf1c40f) + .setTitle(`Greetings to the users of ${guild.name}!`).setDescription(`My name is ${ + this.client.user.username + } and I'd like to thank you for inviting me. I am a helpful and fantastic bot created with Klasa, a discord.js framework.\n + If you want so see my awesome commands, feel free to do ${guild.settings.get( + "prefix" + )}help. I will send you my help menu where you will be provided with more information.\n If you found something not quite right or have a suggestion, please use my report command and let my creator know! I do have a TOS for some of my abilities so please refer to [this link](https://github.com/Butterstroke/MargarineBot/blob/master/TermsOfService.md) for more information. I look forward to having fun with you!`); - - var channel = this.client.util.defaultChannel(guild); - await channel.send({ embed }); - } -}; \ No newline at end of file + + this.client.util.defaultChannel(guild).send({ embed }); + } +}; diff --git a/package-lock.json b/package-lock.json index 78c48fc..69a1ba9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "margarine", - "version": "1.6.1", + "version": "1.6.2", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index 2e9b41e..4e6f565 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "margarine", - "version": "1.6.1", + "version": "1.6.2", "description": "Javascript bot using the Klasa framework", "main": "index.js", "private": true, diff --git a/utilities/utilExport.js b/utilities/utilExport.js index ab4f458..ff21ffc 100644 --- a/utilities/utilExport.js +++ b/utilities/utilExport.js @@ -69,6 +69,7 @@ exports.util = { return guild.channels.cache.get(guild.settings.modlog); } + let client = guild.client; let name = ["general", "general-chat", "off-topic"]; let channelID = Array.from(guild.channels.cache).filter( (channel) => name.includes(channel[1].name) && channel[1].type === "text" @@ -82,7 +83,7 @@ exports.util = { let currChannel = channels[x][1]; if ( currChannel.type === "text" && - currChannel.permissionsFor(guild.members.cache.get(this.client.user.id)).has("SEND_MESSAGES") + currChannel.permissionsFor(guild.members.cache.get(client.user.id)).has("SEND_MESSAGES") ) { channelID = currChannel; x = channels.length; @@ -101,8 +102,8 @@ exports.util = { if (!msg.member.voice.channelID) { msg.sendLocale("MUSICCHECK_USERNOVC"); return false; - } - + } + if (tag !== "join") { let handler = msg.client.music.get(msg.guild.id); if (!handler) { @@ -126,7 +127,10 @@ exports.util = { * @return { String } */ toTitleCase: (text) => { - return text.split(" ").map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" "); + return text + .split(" ") + .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) + .join(" "); }, /** * Generate a Date display for printing