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