【问题标题】:discord.py get webhooks of channeldiscord.py 获取频道的 webhook
【发布时间】:2021-03-13 16:37:52
【问题描述】:

我正在尝试制作一个 webhook,所以如果有人说“ez”,它会删除它并使用带有随机消息的 webhook 发送一条消息。原来我在做的是

    if "ez" in message.content:
        webhook = await message.create_webhook(name=ctx.author.name)
        await webhook.send(ezmessages[random.randint(0, len(ezmessages))-1], username=message.author.name, avatar_url=message.author.avatar_url)
        await message.delete()
        await webhook.delete()

但问题是,如果 webhook 的创建和删除速度过快,则会受到速率限制。因此,我想要做的是检查机器人是否已经有一个用于文本通道的 webhook,如果有一个使用它,但如果没有使用另一个。我认为这会起作用:

    for webhook in message.channel.webhooks:
        await webhook.send(ezmessages[random.randint(0, len(ezmessages))-1], username=message.author.name, avatar_url=message.author.avatar_url)

但我得到了错误

TypeError: 'method' object is not iterable

即使它应该返回 list

有人知道如何正确地迭代这个吗?

【问题讨论】:

    标签: discord discord.py webhooks


    【解决方案1】:

    TextChannel.webhooks不是属性,是函数,是协程,需要调用等待

    webhooks = await message.channel.webhooks()
    for webhook in webhooks:
        ...
    

    docs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-16
      • 2019-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-19
      • 1970-01-01
      相关资源
      最近更新 更多