小编Aha*_*n K的帖子

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

我正在尝试找出如何从我的 Discord 机器人发送的消息中删除嵌入内容。作为一个笑话,我创建了一个机器人来“审查”某些链接,但这并不意味着机器人会重新发布链接本身。假设来自机器人的任何消息中只有一个链接,我如何防止链接嵌入发生,或者让机器人立即删除嵌入?

不是这个问题的重复,因为我不知道链接是什么,所以我不能只找到某个子字符串并在它周围加上尖括号。

我的代码如下:

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()
Run Code Online (Sandbox Code Playgroud)

(此外,如果有更好的方法来进行声明if,请告诉我。)

python python-3.x discord discord.py

4
推荐指数
1
解决办法
3304
查看次数

标签 统计

discord ×1

discord.py ×1

python ×1

python-3.x ×1