Search code examples
javascriptnode.jsbotsdiscorddiscord.js

How do you mass create channels on Discord.js


Hello I am making a bot that will basically make a whole discord server and I just can't figure out how to mass create channels so could someone tell me, please


Solution

  • const Channels = ["Example Channel", "Example Channel 2"]; // Example of channel names.
    const Guild = await client.guilds.create("My Guild"); // Creating the guild.
    
    Channels.forEach(channelName => { // Looping through Channels array to get the channels names.
        Guild.channels.create(channelName); // Creating the channels.
    });
    
    const GuildChannel = Guild.channels.cache.filter(c => c.type === "text").find(x => x.position == 0); // Getting the first channel in the guild.
    const Invite = await GuildChannel.createInvite({maxAge: 0, maxUses: 1}); // Creating and invite.
    message.channel.send(`I created the guild ${Guild.name}. Invite Link: ${Invite.url}`); // Sending the invite link to the current channel.
    
    // Warning: client.guilds.create() is only available to bots in fewer than 10 guilds.guilds!