[英]I am getting an Attribute Error for delete_message, how should I fix this?
I am making a bot command which deletes the last 200 messages in a certain channel.我正在制作一个 bot 命令,它删除某个频道中的最后 200 条消息。 You have to have a certain role to execute the command successfully.
您必须具有一定的角色才能成功执行命令。
I am getting an AttributeError that 'Bot' does not have the attribute 'delete_message'.我收到一个 AttributeError ,即“Bot”没有“delete_message”属性。 How should I fix this?
我应该如何解决这个问题?
@client.command(pass_context = True)
@commands.has_role("watch announcement purger")
async def clear(ctx):
channel = client.get_channel(535156631760273428)
clearLimit = 200
await client.delete_message(ctx.message)
async for x in channel.history(limit = clearLimit):
await client.delete_message(x)
Use Message.delete
and TextChannel.purge
使用
Message.delete
和TextChannel.purge
@client.command()
@commands.has_role("watch announcement purger")
async def clear(ctx):
channel = client.get_channel(535156631760273428)
await ctx.message.delete()
await channel.purge(limit=200)
You're using syntax from a version of discord.py, v0.16, that isn't supported anymore.您正在使用 discord.py v0.16 版本中不再受支持的语法。
See the guide for migrating to v1 .请参阅迁移到 v1 的指南。
I simply use this code:我只是使用这个代码:
@commands.has_permissions(manage_messages=True)
async def clear(ctx,limit:int):
await ctx.channel.purge(limit=limit+1)
await ctx.send(f"Cleared {limit} messages", delete_after=5)
I think this may help with the issue.我认为这可能有助于解决这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.