Python Discord.py |邀请链接 on_ready 问题

标签 python python-3.x python-3.6 discord discord.py

通过我的代码,我尝试向其所在的每个服务器的控制台发送邀请链接,在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/

相关文章:

python - Google Assistant API,控制连接到 Google Home 的电灯开关

python - 无法导入守护程序类

python - 有没有办法在 ContextDecorator 中访问函数的属性/参数?

python - 比较python中的2个字典并创建一个包含字典值的列表

python - 单击后如何保持 PyGTK AppIndicator 菜单打开?

python - Pandas 获取多列的排序索引顺序

python - 使用 python/pandas 将任意多列转换为键值对

python - Pip3 不适用于 OS X

python - 在 python (pytest) 测试中使用资源文件

python - __name__ 在 TypeVar, NewType 中的用途