The-SourceCode/Discord.js-Bot-Development

message.guild.channels.find is not a function

RhysLees opened this issue · 0 comments

(node:24744) UnhandledPromiseRejectionWarning: TypeError: message.guild.channels.find is not a function

const { MessageEmbed } = require("discord.js");
const { stripIndents } = require("common-tags");

module.exports = {
name: "report",
category: "moderation",
description: "Reports a member",
usage: "<mention | id>",
run: async (client, message, args) => {
if (message.deletable) message.delete();

    let rMember = message.mentions.members.first() || message.guild.members.get(args[0]);
    if (!rMember)
        return message.reply("Couldnt find that person").then(m => m.delete(5000));

    if(rMember.hasPermission("BAN_MEMBERS") || rMember.user.bot)
        return message.reply("Can't report that member").then(m => m.delete(5000));

    if(!args[1])
        return message.channel.send("Please provide a reason for the report!").then(m => m.delete(5000));
    
    const channel = message.guild.channels.find(c => c.name === "reports")

    if(!channel)
        return message.channel.send("I cound not find a `#reports` channel").then(m => m.delete(5000));

    const embed = new MessageEmbed()
        .setColor("#FF0000")
        .setFooter(message.guild.name, message.guild.iconURL())
        .setThumbnail(member.user.displayAvatarURL())
        .setAuthor("Reported member", rMember.user.displayAvatarURL())
        .setDescription(stripIndents`**> Member:** ${rMember} (${rMember.id})
        **> Reported by:** ${message.member} (${message.member.id})
        **> Reported In:** ${member.channel}
        **> Reason:** ${args.slice(1).join(" ")}`)
        .setTimestamp();

    return channel.send(embed);
}

}