discord.js not sending to custom channel

I made a command that allows for a user to set a moderation channel. The set channel command works and sends the guild ID, and the channel ID into a JSON file like so:


But in my unban command I can’t seem to get it to send to the channel that was created inside the moderationChannel.json file it just returns with:

modChannel.send is not a function

Here is the code in the unban.js file:

let channels = JSON.parse(fs.readFileSync("././database/moderationChannel.json", "utf8"))
  let modChannel = channels[message.guild.id].channel;

    if(isNaN(args[0])) return message.channel.send(`${switchc} You need to provide an ID.`)
    let bannedMember = await bot.user.fetch(args[0]) || message.guild.members.cache.get(args[0])
        if(!bannedMember) return message.channel.send(`${switchc} Please provide a user id to unban someone!`)

    let reason = args.slice(1).join(" ")
        if(!reason) reason = `${switchc} No reason given!`

    if(!message.guild.me.hasPermission(["BAN_MEMBERS", "ADMINISTRATOR"])) return message.channel.send(`${switchc} I dont have permission to perform this command!`)|
    try {
        message.guild.members.unban(bannedMember, reason)
        const bEmbed = new MessageEmbed()
.setDescription(`**${bannedMember.tag}** has been unbanned!`)

    } catch(e) {
let mEmbed = new MessageEmbed()
  .setTitle(`Member Unbanned`)
  .setDescription("I WORK!")

I used the code for the channels from my prefix command where you set the prefix for a guild. I don’t know why it will not work for sending message in a channel set for a certain guild.

If you need the code where we set the channel the code is below.

  let channels = JSON.parse(fs.readFileSync("././database/moderationChannel.json"));
  channels[message.guild.id] = {
    channel: message.channel.id
  fs.writeFile("././database/moderationChannel.json", JSON.stringify(channels), (err) => {
    if(err) console.log(err)
  let sEmbed = new MessageEmbed()
  .setTitle(`${message.guild.name} Channel Set`)
  .setDescription(`Set to ${message.channel.name}`);

3 thoughts on “discord.js not sending to custom channel”

Leave a Comment