fix(*): Fix broken channel deletion and add more helpful logs

This commit is contained in:
2020-11-16 23:04:21 +00:00
parent f32441716f
commit 6eb1bf5c8a
+8 -6
View File
@@ -218,16 +218,18 @@ function makeTempChannel(message, adventureMessage) {
function deleteChannel(message, channelName) { function deleteChannel(message, channelName) {
try { try {
// Get a Channel by Name // Get a Channel by Name
const fetchedChannel = message.guild.channels.cache.find(channel => channel.name === channelName); const fetchedChannel = message.guild.channels.cache.find(channel => channel.name == channelName);
} catch (error) {
logger.error(`Tried to find a channel called ${channelName} ready for deleting: `, error);
}
try {
logger.info(`Deleting temp channel ${channelName}`) logger.info(`Deleting temp channel ${channelName}`)
fetchedChannel.delete(); fetchedChannel.delete();
} catch (error) { } catch (error) {
logger.error(`Tried to delete channel ${channelName}: `, error); logger.error(`Tried to delete channel ${channelName}: `, error);
let names = [];
message.guild.channels.cache.forEach(channel => {
names.push(channel.name);
});
logger.info(`Channel names in cache: ${names}`);
} }
} }
@@ -380,7 +382,7 @@ client.on('message', function (message) {
} }
else { else {
message.channel.send(`${message.author.username} is not allowed to delete this channel.`); message.channel.send(`${message.author.username} is not allowed to delete this channel.`);
logger.log('info', `${message.author.username} attempted to delete channel ${message.channel.id} but it's not their adventure channel.`); logger.log('info', `${message.author.username} attempted to delete channel ${message.channel.name} but it's not their adventure channel.`);
} }
} }