使用我的代码,我尝试将邀请链接发送到它所在的每个服务器的控制台,在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
答案 0 :(得分:0)
文档在这一点上有点过时了。您只能为频道创建邀请。
过去,服务器具有默认频道,因此服务器邀请实际上是对该默认频道的邀请。
旧服务器的默认频道已加入,但新服务器将没有默认频道。
答案 1 :(得分:0)
您可以直接创建第一个可用频道的邀请,而在很多情况下,邀请都是在应用程序本身中完成的,因此请执行以下操作:
@client.event
async def on_ready():
print(client.servers)
for server in client.servers:
for channel in server.channels:
if channel.type == 'Text':
invitelinknew = await client.create_invite(destination=channel])
print(invitelinknew)
break