gpt4 book ai didi

python - 从 Discord.py 中的消息中删除嵌入

转载 作者:行者123 更新时间:2023-12-05 03:29:49 25 4
gpt4 key购买 nike

我正在尝试弄清楚如何从我的 Discord 机器人发送的消息中删除嵌入。开个玩笑,我做了一个机器人来“审查”某些链接,但这并不是故意的,机器人会重新发布链接本身。假设来自机器人的任何消息中只有一个链接,我该如何防止链接嵌入发生,或者让机器人立即删除嵌入?

不是 this question 的副本因为我不知道链接是什么,所以我不能只找到某个子字符串并将其放在尖括号中。

我的代码如下:

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 语句,请告诉我。)

最佳答案

解释

这可以通过将 SUPPRESS_EMBEDS 标志设置为 True 来实现,前提是您的机器人具有 MANAGE_MESSAGE 权限。在 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)

引用

Message Flags

discord.Message.edit

关于python - 从 Discord.py 中的消息中删除嵌入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70951612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com