DM具有公会ID的邀请?

时间:2020-10-24 19:18:37

标签: python discord discord.py discord.py-rewrite

我有这段代码,该代码应该向命令用户发送仅具有公会ID的公会邀请,但似乎不起作用。

这是代码:

@client.command(name='dm')
async def _dm(ctx):
    guild = client.get_guild(712594852864589885)
    channel = guild.channels[0]
    invitelink = await channel.create_invite(max_uses=1)
    await ctx.author.send(invitelink)

这是错误:


Ignoring exception in command dm:
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 83, in wrapped
    ret = await coro(*args, **kwargs)
  File "main.py", line 30, in _dm
    invitelink = await channel.create_invite(max_uses=1)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/abc.py", line 732, in create_invite
    data = await self._state.http.create_invite(self.id, reason=reason, **fields)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 223, in request
    raise NotFound(r, data)
discord.errors.NotFound: 404 Not Found (error code: 10003): Unknown Channel

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 892, in invoke
    await ctx.command.invoke(ctx)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 797, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 92, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NotFound: 404 Not Found (error code: 10003): Unknown Channel

有人可以帮我吗?谢谢!

1 个答案:

答案 0 :(得分:0)

您可以使用以下功能来做到这一点: 等待fetch_invite(url,*,with_counts = True)。

有关此功能的更多信息,请参见discord.py API refrence