【发布时间】:2021-07-06 23:13:42
【问题描述】:
我想发出一个命令,让机器人可以清除 DM 发送给作者的每条消息。我该怎么做?
【问题讨论】:
-
您只能删除自己在 DM 中的消息
标签: python python-3.x discord discord.py bots
我想发出一个命令,让机器人可以清除 DM 发送给作者的每条消息。我该怎么做?
【问题讨论】:
标签: python python-3.x discord discord.py bots
您可以定义发送给作者的消息,然后在满足条件 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
请注意,机器人无法删除您的消息。
【讨论】: