简体   繁体   English

我收到 delete_message 的属性错误,我应该如何解决这个问题?

[英]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.deleteTextChannel.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.

相关问题 为什么我会收到属性错误? 我该如何解决? - Why am I getting an attribute error? How can I fix it? 我不断收到错误消息 AttributeError: 'pandas._libs.properties.AxisProperty' object has no attribute 'unique'。 我应该如何解决这个错误? - I keep getting the error message AttributeError: 'pandas._libs.properties.AxisProperty' object has no attribute 'unique'. How should I fix this error? 我收到类中定义的属性的属性错误。 我怎样才能解决这个问题? - I am getting an attribute error for an attribute defined inside the class. How can I fix this? AttributeError: 'Bot' 对象没有属性 'delete_message' - AttributeError: 'Bot' object has no attribute 'delete_message' 我收到“SystemExit: 2”错误,如何修复 - I am getting 'SystemExit: 2' error , how to fix it 我正在尝试读取文件夹路径,但我收到 'str' has no attribute 'dir' 错误消息 - I am trying to read a folder path but I am getting the 'str' has no attribute 'dir' error message 为什么我收到 JSON 错误,我该如何解决 - Why am I getting a JSON error and how do I fix it 使用类时如何修复属性错误 - How am I able to fix an attribute error when using classes AttributeError: 'NoneType' object 没有属性 'attrs',我在尝试从 url 抓取图像时遇到此错误。 我该如何解决? - AttributeError: 'NoneType' object has no attribute 'attrs', I am getting this error while I am trying to scrape images from the url. How can I fix it? Python Telegram Bot delete_message (aiogram) - Python Telegram Bot delete_message (aiogram)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM