message.guild.channels.find is not a function

Confused Newbie

people of the internet! I am quite new to programming and I am trying to work on a Discord bot as a means of learning.

I am trying to find a channel by name and send a message to it after kicking a member (it's a kick command). The error I am getting is message.guild.channels.find is not a function.

I am not sure what to do here, and I am unable to get it to work for some reason.

 if (cmd === prefix + "kick") {
    let kUser = message.guild.member(
      message.mentions.users.first() || message.guild.member.length(args[0])
    );
    if (!kUser) return message.channel.send("Can't find user!");
    let kReason = args.join(" ").slice(22);
    if (!message.member.hasPermission("MANAGE_MESSAGES"))
      return message.channel.send("No can do pal!");
    if (kUser.hasPermission("MANAGE_MESSAGES"))
      return message.channel.send("That person can't be kicked");

    let kickEmbed = new Discord.MessageEmbed()
      .setDescription("Kick")
      .setColor("#f418")
      .addField("Kicked User" + kUser + "With ID" + kUser.id)
      .addField(
        "Kicked By",
        "<@" + message.author.id + ">" + "With ID : " + message.author.id
      )
      .addField("Time", message.createdAt)
      .addField("Reason", kReason);

    let kickChannel = message.guild.channels.find(channel => channel.name === "logs");
    if (!kickChannel) return message.channel.send("Can't find logs channel.");

    message.guild.member(kUser).kick(kReason);

    // kickChannel.send(kickEmbed);

    return;
  }

Thank you in advance!

Syntle

Since discord.js v12 you need to access the channels collection using cache so your solution would be:

let kickChannel = message.guild.channels.cache.find(channel => channel.name === "logs");

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TypeError: message.guild.channels.find is not a function discord.js

TypeError: message.guild.channels.cache is not a function

message.guild.roles.find is not a function

TypeError: message.guild.channels.forEach is not a functionl

message.guild.createChannel is not a function

How to fetch a message in a channel gotten via guild.channels.get

guild.channels.filter is not a function discord.js

How do I change message.guild.channels.some in order to make it to work in V12?

How to get the number of voice channels in a guild?

How do I define the guild I want to use ".channels" on?

How do I delete all channels in a guild discord.js

guild.members.forEach is not a function

Get guild ID from on_message

Is it possible to send a message to every guild my bot is in?

"member.guild.username" is displayed as "undefined" in a message

message.guild.members.getMember not working

message.guild returns null in discordjs

How to fetch a message from the entire guild

guild.text_channels return just the top channel instead of all channels

Why is "message.channel.find" not a function?

Django Channels not sending reply message

Is there a way to find out the guild name with only the ID?

How to include guild name in welcome message using discord.py

Edit message in a specific channel in a specific guild | Discord.js

discordjs message.guild.roles.size returns null in serverinfo command

Is there a way to access message.guild.name in a ready event?

discord.py - Can't send message to channel in other guild

Create new message chain out of existing channels

Tracing input & output of message channels of Spring Integration