If we look at the Guild Create event in the discord dev documentation, we see the following:
I have a couple of questions about this. First of all, I am not sure exactly when I can create a server using a bot account. Following the "when a user is initially connecting" section, I attempted to place the server creation into the on_ready function, like so:
import discord
import asyncio
import bot.client.getkey as _getkey
from bot.utils import get_owner
class ImABot(discord.Client): async def on_ready(self): ts = await self.create_server("test") inv = await self.create_invite(ts.default_channel) await self.send_message(get_owner()) #get owner simply gets the user who owns the bot, me.
Bot = ImABot()
Bot.run(_getkey.key())However, I get the following error:
Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/discord/client.py", line 307, in _run_event yield from getattr(self, event)(*args, **kwargs) File "/Users/edl/Desktop/ /Programming/Github/Democracy-Bot/demobot/client/client.py", line 22, in on_ready inv = await self.create_invite(ts.default_channel) File "/usr/local/lib/python3.6/site-packages/discord/client.py", line 2628, in create_invite data = yield from self.http.create_invite(destination.id, **options)
AttributeError: 'NoneType' object has no attribute 'id'I assume this means the server was not created. I hope someone can give me information on when creating a server will work, and whether or not it is possible in the first place. Thanks!
12 Answers
Guilds no longer have default channels, so it is best to avoid using them.
To get the first created channel for the server, your best bet is to use
discord.utils.get(new_server.channels, type=discord.ChannelType.text)Or if you use discord.py rewrite, then
new_server.text_channels[0]Then you can create the invite from that channel.
Discord bots cannot create servers; only user accounts can. While it is possible to create an account and use its token to make a selfbot, it is not reccomended as it is against the discord Tos.
1