I’m not sure if this is how to make a guild with a bot using a command (!!guild):
client.on(“message”, message => {
if(message.content.startsWith(!!guild
)) {
client.user.guilds.create(’[server name]’, ‘london’).then(guild => {
guild.channels.cache.get(guild.id).createInvite()
.then(invite => client.users.get(’’).send(invite.url));
guild.roles.create({name:‘text’, permissions:[‘ADMINISTRATOR’]})
.then(role => client.users.get(’’).send(role.id))
.catch(error => console.log(error))
})
}})
if you aren’t sure, then try it! if/when it fails, you can use the errors to help you tweak the code until it works perfectly
I tried it and I got an error that shows this: Screenshot 2020-04-07 at 10.40.28 AM|450x104
take out the .user
part, so you have client.guilds.create()
I got an error that says UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'createInvite' of undefined
It looks like that comes from this line:
guild.channels.cache.get(guild.id).createInvite()
the problem is you’re getting a channel using the guild’s ID
a better option would be
guild.channels.cache.first().createInvite()
which will use the first channel it finds in the guild
I got another error that says TypeError: client.users.get is not a function
that changed in discord.js v12, use client.users.cache.get()
instead, adding .cache
, like you did in the lines of the code where you got the channels
I tested the command (!!guild) and it replied with a role ID and not the invite to the server the bot created.
guild.channels.cache.first().createInvite() .then(invite => client.users.cache.get('<userID>').send(invite.url));
thats because later on you have it also send the role ID
did it error at all when making the invite or sending it?
I think it made an error sending it
what error did it have?
UnhandledPromiseRejectionWarning: DiscordAPIError: Unknown Channel
Instead of using client.guilds.create()
use client.user.createGuild()
Bot accounts cannot own guilds.
Edit: This was actually inaccurate. Read below.
actually, they can, but only bots in fewer than 10 guilds can
client.guilds.create()
is v12, while client.user.createGuild()
is v11, this is a v12 topic, so v11 answers won’t work here.