I have a logs command but my bot is unable to fetch it
Here is the code for the fetch command:
if (value == "logs") {
let lID = db.get(`${message.guild.id}.lChannel`)
let lChannel = message.guild.channels.get(lID);
if (!lChannel) message.channel.send("There is no log channel set");
if (lChannel) {
const embed = new RichEmbed()
.setTitle('Log Channel')
.setDescription(`The log channel is ${lChannel}`)
message.channel.send(embed)
}
}
You could’ve spent this time constructing your query more and therefore giving us more details so we can help. All I know so far is something isn’t working. What isn’t working? Is there any errors?
here is the set command:
if (args[0] === “logs”) {
let lChannel = message.mentions.channels.first();
if (!lChannel) {
message.channel.send("That channel could not be found");
}
await db.set(`${message.guild.id}.lChannel`, lChannel.id);
let sembed = new RichEmbed()
.setTitle("Success")
.setColor("#3FC83B")
.setDescription(The log channel has been set to <#${lChannel.id}>)
message.channel.send(sembed);
}
Since I have no idea what’s happening, i have rewrote the get code, please replace everything inside value == logs with:
const lID = db.get(`${message.guild.id}.lChannel`);
if (!lID) return message.channel.send("There is no log channel set");
const lChannel = message.guild.channels.get(lID);
if (!lChanel) return message.channel.send("The log channel has been removed, set a new one");
const Embed = new RichEmbed()
.setTitle('Log Channel')
.setDescription(`The log channel is ${lChannel}`);
message.channel.send(Embed);
I think I’ve got it. So you’re fetching the channel based upon the raw lID value. If the channel doesn’t exist then its not set. But, the lID is an array, so you would have to do…
let lChannel = message.guild.channels.get(lID[0]);
if (value == "welcome") {
let wID = db.get(`${message.guild.id}.wChannel`)
let wChannel = message.guild.channels.get(wID[0]);
if(!wChannel) return message.channel.send("There is no welcome channel set");
const embed = new RichEmbed()
.setTitle('Welcome Channel')
.setDescription(`The welcome channel is ${wChannel}`)
message.channel.send(embed)
}