【问题标题】:How do I delete the messages from a user's DMS如何从用户的 DMS 中删除消息
【发布时间】:2021-07-06 23:13:42
【问题描述】:

我想发出一个命令,让机器人可以清除 DM 发送给作者的每条消息。我该怎么做?

【问题讨论】:

  • 您只能删除自己在 DM 中的消息

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


【解决方案1】:

您可以定义发送给作者的消息,然后在满足条件 x 后将其删除。

看看下面的例子:

import asyncio

@client.command()
async def testdm(ctx):
test = await ctx.author.send("This is a test")
await asyncio.sleep(5) # For example if you want to wait 5 seconds
await test.delete()

根据 Łukasz Kwieciński 的评论,您也可以使用:

await ctx.author.send("This is a test", delete_after=5) # Seconds are customizable

请注意,机器人无法删除您的消息。

【讨论】:

  • 一种更简单的方法是在 ctx.author.send 中添加 delete_after kwarg
猜你喜欢
  • 1970-01-01
  • 2021-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-21
  • 2011-12-29
  • 2019-12-27
  • 1970-01-01
相关资源
最近更新 更多