Aha*_*n K 4 python python-3.x discord 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,请告诉我。)
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3304 次 |
| 最近记录: |