Python 删除以特定前缀[discord.py]开头的邮件
我希望我的bot删除所有不以前缀Python 删除以特定前缀[discord.py]开头的邮件,python,discord,discord.py,Python,Discord,Discord.py,我希望我的bot删除所有不以前缀开头的邮件。到目前为止,我在discord.py中编写了这段代码,但它一直在删除所有消息 @Client.event 异步def on_消息(消息): 如果message.author.has_角色(“Bot”): 回来 elif message.content.startswith('.'): 回来 其他: 等待消息。删除() 提前谢谢我会这样做: @Client.event async def on_message(message): if mess
开头的邮件。到目前为止,我在discord.py中编写了这段代码,但它一直在删除所有消息
@Client.event
异步def on_消息(消息):
如果message.author.has_角色(“Bot”):
回来
elif message.content.startswith('.'):
回来
其他:
等待消息。删除()
提前谢谢我会这样做:
@Client.event
async def on_message(message):
if message.content.startswith(".") == False:
message.channel.purge(limit=1)
else:
pass
试着这样做:
@Client.event
async def on_message(message):
if message.content.startswith(".") == False:
message.channel.purge(limit=1)
else:
pass
@client.event
异步def on_消息(ctx):
如果ctx.content.startswith('.'):
等待客户端处理命令(ctx)
回来
对于ctx.author.roles中的角色:
如果role.name==“Bot”:
回来
等待ctx.delete()
没有成员这样的东西。如果您的角色是
,您应该会得到一个属性错误,您是从哪里得到它的?好的,谢谢使用lotUsingpurge
是不好的,因为它可能会删除错误的消息,以防两个消息连续快速发送。只需调用wait message.delete()
,以确保删除了正确的消息。另外,如果条件==False
应该写为如果不是条件
。