Reputation: 23
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?
Upvotes: 1
Views: 6006
Reputation: 6625
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}`);
};
});
Upvotes: 2