【发布时间】:2019-03-01 09:01:11
【问题描述】:
使用我的代码,我尝试向它所在的每台服务器的控制台发送邀请链接,在 discord.py 的 API 中,它说你可以编写服务器或频道,但服务器似乎不适合我。
@client.event
async def on_ready():
print(client.servers)
for value in client.servers:
invitelinknew = await client.create_invite(destination=value)
print(invitelinknew)
我收到以下错误:
Ignoring exception in on_ready
Traceback (most recent call last):
File "C:\Program Files\Python36\lib\site-packages\discord\client.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "C:/Users/Rasmus/Python/discordbot/botnoggi2.py", line 126, in on_ready
invitelinknew = await client.create_invite(destination=value)
File "C:\Program Files\Python36\lib\site-packages\discord\client.py", line 2628, in create_invite
data = yield from self.http.create_invite(destination.id, **options)
File "C:\Program Files\Python36\lib\site-packages\discord\http.py", line 198, in request
raise NotFound(r, data)
discord.errors.NotFound: NOT FOUND (status code: 404): Unknown Channel
我的问题是使用on_ready命令和for循环检查每个服务器,和When running bot sample code, I get this error不一样
编辑:
@client.event
async def on_ready():
for server in client.servers:
channel = next(iter(server.channels))
invitelinknew = await client.create_invite(destination=channel)
print(invitelinknew)
此代码返回:
Traceback (most recent call last):
File "C:\Program Files\Python36\lib\site-packages\discord\client.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "C:/Users/Rasmus/Python/discordbot/botnoggi2.py", line 126, in on_ready
invitelinknew = await client.create_invite(destination=channel)
File "C:\Program Files\Python36\lib\site-packages\discord\client.py", line 2628, in create_invite
data = yield from self.http.create_invite(destination.id, **options)
File "C:\Program Files\Python36\lib\site-packages\discord\http.py", line 198, in request
raise NotFound(r, data)
discord.errors.NotFound: NOT FOUND (status code: 404): Unknown Channel
【问题讨论】:
-
不重复,因为我使用的是 on_ready 而不是 on_member_join 或 on_server_join
-
同样的问题,同样的解决方案。所以它是重复的。
-
stackoverflow.com/questions/47521971/… 已更改 send_message 行作为解决方案,这里我尝试将其打印到控制台
标签: python python-3.x python-3.6 discord discord.py