【问题标题】:Removing an embed from a message in Discord.py从 Discord.py 中的消息中删除嵌入
【发布时间】:2022-02-03 02:15:54
【问题描述】:

我试图弄清楚如何从我的 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 语句,请告诉我。)

【问题讨论】:

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


    【解决方案1】:

    说明

    这可以通过将 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-12
      • 1970-01-01
      • 2018-06-29
      • 2018-07-24
      • 2021-09-08
      • 2021-01-21
      • 2017-06-30
      相关资源
      最近更新 更多