当用户要求机器人这样做时,我试图让我的机器人立即删除所有消息,但我的代码不起作用。
import os
import discord
client = discord.Client()
client = commands.Bot(command_prefix='+')
@client.command(name='effacer')
async def purge(ctx):
async for msg in client.logs_from(ctx.message.channel):
await client.delete_messages(msg)
await ctx.send("Who am I? What is this place? And where the hell did the messages go?")
client.run(TOKEN)
如何修复我的代码以便我的机器人可以删除所有消息?我相信我最大的问题是await client.delete_messages(msg)
,因为Python不断地说客户端没有属性delete_messages
.
删除每条消息都会限制机器人的速率,从而产生性能问题,这也会减慢机器人的速度。相反,如果机器人只是删除该频道并在完全相同的位置对其进行克隆,那么效率会更高。
这是您的命令中包含的清除
@client.command(name='effacer')
async def purge(ctx):
await ctx.channel.delete()
new_channel = await ctx.channel.clone(reason="Channel was purged")
await new_channel.edit(position=ctx.channel.position)
await new_channel.send("Channel was purged")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)