【发布时间】:2020-01-27 23:52:54
【问题描述】:
如果我们查看 discord 开发文档中的 Guild Create 事件,我们会看到以下内容:
我对此有几个问题。首先,我不确定何时可以使用机器人帐户创建服务器。在“用户最初连接时”部分之后,我尝试将服务器创建放入 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'
我认为这意味着服务器没有创建。我希望有人可以给我关于创建服务器何时可以工作的信息,以及它是否可能首先。谢谢!
【问题讨论】:
-
代码中的错误来自servers are no longer created with a default channel.因此,对于这些新服务器,
server.default_channel设置为None。
标签: python python-3.x bots discord discord.py