无法仅在一台服务器中发送 Webhook

Unable to send a webhook only in one server

代码

webhooks = await message.channel.webhooks()
webhook = discord.utils.get(webhooks, name=message.author.display_name)
if webhook is None:
    webhook = await message.channel.create_webhook(name=message.author.display_name)
await webhook.send(content=content, username=message.author.display_name, avatar_url=message.author.avatar)
await message.delete()

回溯

Ignoring exception in on_message
Traceback (most recent call last):

File "/app/.heroku/python/lib/python3.9/site-packages/discord/client.py", line 382, in _run_event
await coro(*args, **kwargs)

File "/app/cogs/events.py", line 105, in on_message
await webhook.send(content=content, username=message.author.display_name, avatar_url=message.author.avatar)

File "/app/.heroku/python/lib/python3.9/site-packages/discord/webhook/async_.py", line 1508, in send
raise InvalidArgument("This webhook does not have a token associated with it")
discord.errors.InvalidArgument: This webhook does not have a token associated with it

在意图和文本通道中启用了 Webhook。此异常仅在一台服务器中引发,在其他服务器中工作正常。

我在本地系统上测试了相同的代码,本地系统上的客户端 运行 发送 webhook 没有任何问题。

创建每个 webhook 本身是个坏主意 - 您可以快速达到每个通道 10 个 webhook 的速率限制。

相反,API 允许您使用 send 自定义用户名和头像。
在当前版本的 discord 客户端中,点击 webhook 仍然会显示假用户。没有必要为每个用户单独制作一个。

然后你可以这样做:

async def impostor(ctx, user: discord.User, *, msg: str):
    hooks = await ctx.channel.webhooks()
    hook = utils.get(hooks, name='My Impostor Webhook')  # Change this to whatever you want, nobody will see it. This is only displayed to admins checking the webhook list and for the bot to find it again.
    if hook is None:
        hook = await ctx.channel.create_webhook(name='My Impostor Webhook', avatar=None, reason=None)
    await hook.send(content=msg, username=user.name, avatar_url=user.avatar_url)

(请注意,在较新的版本中,这将是 .avatar.url