Alden Vacker
Alden Vacker

Reputation: 99

Deleting all channels doesn't work discord.js

I'm coding a bot that deleting all channels of a Discord server. Here my code :

const { Client, GatewayIntentBits } = require("discord.js");

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
  ],
});

client.on("ready", () => {
  console.log("Bot Ready");
});

client.on("messageCreate", (message) => {
  if (message.author.bot) return;

  console.log(message);
  if (message.content === ".setup") {
    message.guild.channels.forEach((channel) => channel.delete());
  }
});

client.login(
  "token"
);

When I launch it and I execute the command, nothing is happening. My bot is Administrator.

Someone can help me please ?


Alden Vacker

Upvotes: -2

Views: 134

Answers (1)

Kristab
Kristab

Reputation: 21

It has a very easy fix. Just put cache like this:

 message.guild.channels.cache.forEach((channel) => channel.delete());

Upvotes: 1

Related Questions