通过我的代码,我尝试向其所在的每个服务器的控制台发送邀请链接,在discord.py的API中,它说您可以编写服务器或 channel ,但服务器似乎不适合我。
@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
最佳答案
在这一点上,文档有点过时了。您只能为 channel 创建邀请。
服务器曾经有一个默认 channel ,因此服务器邀请实际上是对该默认 channel 的邀请。
较旧的服务器有默认 channel ,但新服务器不会有默认 channel 。
关于Python Discord.py |邀请链接 on_ready 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52503228/