【问题标题】:Discord py - edit webhook message embed in 'on_message'Discord py - 编辑嵌入在“on_message”中的 webhook 消息
【发布时间】:2021-05-04 07:44:03
【问题描述】:

我有一个小问题,我不知道如何解决它。我想编辑一个消息嵌入,如果它被发布,它是由一个不和谐的 webhook 直接发送的。这就是为什么我为此使用“on_message”事件。在正常情况下,您可以只获取消息而不是使用msg.edit,但这不适用于 webhook 消息。

如何在 webhook 发布消息后直接对其进行编辑?我尝试使用 api“discord-webhooks”,但找不到我想要的解决方案。

我试过了:

@bot.event
async def on_message(message):
##### Netflix-News edit ######
    if message.channel.id == 804484025166856262:
            embed = discord.Embed(title=f"{title}",
                                  url=f"{lonk}",
                                  description=f"{descfix}",
                                  color=0xe74c3c)
            embed.set_thumbnail(url=f"https://i.imgur.com/4np2bdK.png")
            embed.set_image(url=f"{Thumbnail}")
            embed.set_footer(text=f"{footer}", icon_url="https://i.imgur.com/4np2bdK.png")
            
            webhook = DiscordWebhook(url='LINKHERE')
            webhook.embed = embed
            await webhook.edit(sent_webhook)

【问题讨论】:

    标签: python python-3.x discord.py webhooks discord.py-rewrite


    【解决方案1】:

    Webhook.edit 编辑 webhook 本身,而不是消息。要编辑消息,请使用Webhook.edit_message

    await webhook.edit_message(message_id, embed=embed)
    

    PS:你没有定义sent_webhook

    参考:

    【讨论】:

    • 我得到 AttributeError: 'DiscordWebhook' 对象没有属性 'edit_message'
    • 你使用的是官方的 discord.py webhooks 吗?看来您正在使用外部库
    • 如何使用默认的 discord webhook? webhook = Webhook.from_url 也不起作用。
    • 我认为这对它自己来说差不多,它是discord.Webhook.from_url,下次稍微思考和基本解决问题的技巧将避免所有这些牵手
    • 您可以传递discord.AsyncWebhookAdapter,这取决于您使用的库。看看examples
    猜你喜欢
    • 1970-01-01
    • 2021-09-15
    • 2022-01-20
    • 2019-10-02
    • 2020-08-17
    • 1970-01-01
    • 2018-12-04
    • 2021-08-12
    • 2021-03-23
    相关资源
    最近更新 更多