Python 使用Discord Bot创建服务器
如果我们查看discord dev文档中的Python 使用Discord Bot创建服务器,python,python-3.x,bots,discord,discord.py,Python,Python 3.x,Bots,Discord,Discord.py,如果我们查看discord dev文档中的Guild Create事件,我们会看到以下内容: 我有几个问题要问。首先,我不确定何时可以使用bot帐户创建服务器。在“用户最初连接时”部分之后,我尝试将服务器创建放在on_ready函数中,如下所示: import discord import asyncio import bot.client.getkey as _getkey from bot.utils import get_owner class ImABot(discord.Clie
Guild Create
事件,我们会看到以下内容:
我有几个问题要问。首先,我不确定何时可以使用bot帐户创建服务器。在“用户最初连接时”部分之后,我尝试将服务器创建放在on_ready
函数中,如下所示:
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())
但是,我得到以下错误:
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'
我认为这意味着服务器没有被创建。我希望有人能告诉我什么时候创建一个服务器会起作用,以及它是否可能在第一时间。谢谢 公会不再有默认频道,因此最好避免使用它们 要获得为服务器创建的第一个频道,最好使用
discord.utils.get(new_server.channels, type=discord.ChannelType.text)
或者如果使用discord.py重写,则
new_server.text_channels[0]
然后您可以从该频道创建邀请。Discord bots无法创建服务器;只能使用用户帐户。虽然可以创建一个帐户并使用其令牌创建selfbot,但它不会被重新注册。代码中的错误来自以下事实:。因此,
server。对于这些新服务器,默认的\u频道
设置为None
。的文档中另有说明:“超过10个公会中的机器人帐户不允许创建公会。”因此,大概10个或更少公会中的机器人帐户可以创建公会