How to convert this code in such a way as to get id from channel but also from guild? At the present moment, I am getting the error:
const { id } = msg.channel
^
SyntaxError: Identifier 'id' has already been declared
at wrapSafe (internal/modules/cjs/loader.js:1053:16)
at Module._compile (internal/modules/cjs/loader.js:1101:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at module.exports (C:\Users---------------------\src\handlers
\event.handler.js:38:19)
at Object.<anonymous> (C:\Users---------------------\src\index.js:21:1)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
[nodemon] app crashed - waiting for file changes before starting...
Event code:
const { Collection, MessageEmbed, Client } = require("discord.js")
const chalk = require("chalk")
const { readdirSync, readFileSync, writeFileSync } = require("fs")
const fs = require('fs')
const path = require('path')
module.exports = {
name: "channelDelete",
run(msg){
//////////////////////////////////////
const { channel, guild } = msg
const { id } = msg.guild
const { id } = msg.channel
const guildID = id
const client = new Client()
client.settings = new Collection()
///////////////////////////////////////
const log = console.log
// Wczytywanie danych z pliku
fs.readFile(__dirname + `./../config/servers/${guildID}.yaml`, "utf8", (err, jsonString) => {
if (err) {
console.log("The file cannot be loaded:", err)
return
}
const data = JSON.parse(jsonString)
console.log(data.channelLogID)
if(data.channelLogID === "None"){
return
} else {
const embed = new MessageEmbed()
.setTitle("Channel deleted")
.setDescription(channel.id)
.setColor(0xcc0000)
msg.client.channels.cache.get(data.channelLogID).send(embed)
}
})
}
}
I can't do anything about it and every attempt ends with a mistake. There is maybe another easy way to log a guild?