Is there any way to get a bot to create a guild on Discord?

Vaneer

I'm using discord.js V12, and I am trying to get my bot to create a guild with a channel in it. However, I'm unable to fix this error "TypeError: channels is not iterable". This is my current code:

client.on("message", async message => {
    if(message.content == "?createGuild") {
        let guild = await client.guilds.create("Test Guild", {channels: {id: 1, type: "text", name: "invite-channel"}}).catch(err => {console.log(err)});        
        let guildchannel = await guild.channels.find(cha => cha.name == "invite-channel");
        let invite = await guildchannel.createInvite({maxAge: 0, unique: true, reason: "Testing."});
        message.channel.send(`https://discord.gg/${invite.code} is the server I created!`);
    }
});

Can anyone help me out?

Jakye

Client.guilds.create takes as a second parameter an options Object. Options.channels takes an Array, containing multiple objects, each object representing a channel. You are providing an Object instead.

Note that everyone can create a Guild since you have no restrictions on this command.


client.on("message", async message => {
    if (message.content == "?createGuild") {
        const Guild = await client.guilds.create("Test Guild", {
            channels: [
                {"name": "invite-channel"},
            ]
        });

        const GuildChannel = Guild.channels.cache.find(channel => channel.name == "invite-channel");
        const Invite = await GuildChannel.createInvite({maxAge: 0, unique: true, reason: "Testing."});
        message.channel.send(`Created guild. Here's the invite code: ${Invite.url}`);
    };
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Guild in the presence of discord bot

Is there any way to get the guild object a command is run it?

Is there a way for a bot to know when a guild member logs in on a discord server?

Discord Bot - Guild Members Showing in count... but not in guild.members

Best way to create a very simple discord bot=

Discord.js how can I create an invite for every guild my bot is in?

Discord bot on_join_guild dm everyone

Multiple guild welcome bot - discord.py

Discord.py bot guild count

Is it possible to get the list of all members from a discord guild using non-bot token?

How to get discord bot to create a channel

Is there any way to have a discord bot in JavaScript and some comands in python?

How to get username of user not in Discord guild?

Discord.js Get the member in a guild by username

How do I get the guild.id from the server when the bot joins discord.js v13

How to make the bot leave a guild with a command in discord.py?

What event is fired when a Discord bot joins a guild?

Discord Bot can only see itself and no other users in guild

Discord Java Bot - listener works for dm's but not guild messages?

Trying to show all members of guild by bot, Discord JS

Discord bot not seeing guild members and new members joining

How can I access to the guild IDs (Discord Bot)

How to get members of a discord guild(discord.py)?

Discord.py | How can I make the bot tag the owner of the guild on joining the guild?

Is there a way to get the guild's notification settings?

i create a discord level bot but it get error say not defined

Using Discord.js, is there a way to ban a user who is not in the current guild?

With discord.py, whats a way to get my discord bot to display a custom message in the 'playing' section on the members tab?

How to get the ID of a guild on join in Discord.js