Python 删除 Discord.py 中的用户消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42182243/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 21:20:15  来源:igfitidea点击:

Deleting User Messages in Discord.py

pythondiscord

提问by Hardline_98

Is there any way to delete a message sent by anyone other than the bot itself, the documentation seems to indicate that it is possible

有没有办法删除机器人本身以外的任何人发送的消息,文档似乎表明这是可能的

Your own messages could be deleted without any proper permissions. However to delete other people's messages, you need the proper permissions to do so.

您自己的消息可能会在没有任何适当权限的情况下被删除。但是,要删除其他人的消息,您需要适当的权限才能这样做。

But I can't find a way to target the message to do so in an on_message event trigger, am I missing something or is it just not possible?

但是我找不到在 on_message 事件触发器中定位消息的方法,是我遗漏了什么还是不可能?

采纳答案by ocelot

Yup, it should be possible.

是的,应该是可以的。

You need the bot/user account to have the "Manage Messages" permission.

您需要机器人/用户帐户才能拥有“管理消息”权限。

@client.event
async def on_message(message):
    await client.delete_message(message)

So, the event would occur something like

所以,事件会发生类似

>User sends message
>Bot detects that the user has sent a message
>Bot deletes the message that the user sent

Hopefully from this you should be able to see how user messages are deleted, just ensure that the bot/user account as the "Manage Messages" permission.

希望从中您应该能够看到如何删除用户消息,只需确保将机器人/用户帐户设置为“管理消息”权限即可。