【发布时间】:2021-05-18 17:15:49
【问题描述】:
所以我创建的机器人(在 python 中)当前可以使用命令“!清除所有”删除所有消息。但是,我还想为其添加一个功能,以便人们可以输入“x”数量,然后将其删除而不是全部删除。这可能吗?还是我需要以不同的方式重做这个功能? 我应该补充一下,我是 python 新手,还在学习。
这是我的代码:
if '!clear all' in message.content and message.author.permissions_in(message.channel).manage_messages:
await message.channel.send('__**This will delete all messages (even pinned)**__')
await message.channel.send('**Type:**')
await message.channel.send('```"!yes" to continue```')
await message.channel.send('```"!no" to stop```')
if '!no' in message.content and message.author.permissions_in(message.channel).manage_messages:
await message.channel.send('**This proccess has stopped**')
exit()
else:
if '!yes' in message.content and message.author.permissions_in(message.channel).manage_messages:
await message.channel.send('**This proccess will continue in:**')
await message.channel.send('**3**')
await asyncio.sleep(0.5)
await message.channel.send('**2**')
await asyncio.sleep(0.5)
await message.channel.send('**1**')
deleted = await message.channel.purge(limit=3000)
await message.channel.send('**All messages deleted. Have a nice day**'.format(deleted))
await asyncio.sleep(3)
deleted = await message.channel.purge(limit=3000)
非常感谢!
【问题讨论】: