簡體   English   中英

從 Discord.py 中的消息中刪除嵌入

[英]Removing an embed from a message in Discord.py

我試圖弄清楚如何從我的 Discord 機器人發送的消息中刪除嵌入。 開個玩笑,我做了一個機器人來“審查”某些鏈接,但這並不意味着,機器人會重新發布鏈接本身。 假設來自機器人的任何消息中只有一個鏈接,我該如何防止鏈接嵌入發生,或者讓機器人立即刪除嵌入?

不是這個問題的重復,因為我不知道鏈接是什么,所以我不能只找到某個 substring 並在它周圍加上尖括號。

我的代碼如下:

if any(substring in message.content.lower() for substring in ["www.example.com", "www.wikipedia.com"]):
    msg = await message.channel.send(f"{message.author.mention} is out of line!"
                                     f"\n> {message.content}\nThis misdeed has been noted, "
                                     "and future transgressions will result in severe penalties.")
    # remove embeds here?
    await message.delete()

(此外,如果有更好的方法來執行if語句,請告訴我。)

解釋

如果您的機器人具有MANAGE_MESSAGE權限,這可以通過將SUPPRESS_EMBEDS標志設置為 True 來完成。 在 discord.py 中,這將在Message.edit方法中,您在其中將suppress參數設置為True

代碼

if any(substring in message.content.lower() for substring in ["www.example.com", "www.wikipedia.com"]):
    msg = await message.channel.send(f"{message.author.mention} is out of line!"
                                     f"\n> {message.content}\nThis misdeed has been noted, "
                                     "and future transgressions will result in severe penalties.")
    # remove embeds here!
    await message.edit(suppress=True)

參考

消息標志

discord.Message.edit

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM