mirror of
https://github.com/jcreek/denBot.git
synced 2026-07-13 02:43:46 +00:00
refactor(*): Delete channels using names not ids
This commit is contained in:
@@ -152,14 +152,18 @@ function makeTempChannel(message, adventureMessage) {
|
|||||||
.catch(logger.error);
|
.catch(logger.error);
|
||||||
|
|
||||||
// Delete the channel after the configured amount of minutes
|
// Delete the channel after the configured amount of minutes
|
||||||
setTimeout(function(){ deleteChannel(message, createdChannelId); }, (config.channeldeletetimeinminutes * 1000 * 60) );
|
setTimeout(function(){ deleteChannel(message, channelName); }, (config.channeldeletetimeinminutes * 1000 * 60) );
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteChannel(message, channelId) {
|
function deleteChannel(message, channelName) {
|
||||||
// For some reason this errors without the console.log loading the cache first - not sure why
|
try {
|
||||||
console.log(message.guild.channels.cache);
|
// Get a Channel by Name
|
||||||
const fetchedChannel = message.guild.channels.cache.get(channelId);
|
const fetchedChannel = message.guild.channels.cache.find(channel => channel.name === channelName);
|
||||||
|
|
||||||
fetchedChannel.delete();
|
fetchedChannel.delete();
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client.on('message', function (message) {
|
client.on('message', function (message) {
|
||||||
@@ -287,7 +291,7 @@ client.on('message', function (message) {
|
|||||||
if (command === 'dc') {
|
if (command === 'dc') {
|
||||||
// todo - add logic here to determine if they can delete the channel (i.e. it's their temporary one) - compare the name
|
// todo - add logic here to determine if they can delete the channel (i.e. it's their temporary one) - compare the name
|
||||||
if (message.channel.name === getChannelName(message.author.username)) {
|
if (message.channel.name === getChannelName(message.author.username)) {
|
||||||
deleteChannel(message, message.channel.id)
|
deleteChannel(message, message.channel.name)
|
||||||
logger.log('info', `${message.author.username} deleted their adventure channel.`);
|
logger.log('info', `${message.author.username} deleted their adventure channel.`);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
Reference in New Issue
Block a user