因此,我正在制作一个警告系统,我几乎完成了,但有一个问题,我必须添加一个清除警告命令,清除特定用户的所有警告。。。但我不知道怎么做。这是我的密码-
@client.command(pass_context = True)
@commands.has_permissions(manage_roles=True, ban_members=True)
async def warn(ctx,user:discord.User,*reason:str):
if not reason:
await ctx.send("Please provide a reason")
return
reason = ' '.join(reason)
for current_user in report['users']:
if current_user['name'] == user.name:
current_user['reasons'].append(reason)
await ctx.send("reported sir!")
await user.send(f"u have been reported for :{reason}")
break
else:
report['users'].append({
'name':user.name,
'reasons': [reason,]
})
with open('reports.json','w+') as f:
json.dump(report,f)
@client.command(pass_context = True, aliases=["warns"])
async def warnings(ctx,user:discord.User):
for current_user in report['users']:
if user.name == current_user['name']:
embed = discord.Embed(title="Reports:", description=(f"{user.name} has been reported {len(current_user['reasons'])} times : {','.join(current_user['reasons'])}"))
await ctx.send(embed= embed)
break
else:
await ctx.send(f"{user.name} has never been reported")
首先,让我指出代码中的错误
不会执行
if
块,因为原因没有默认值,请使用reason:str = None
设置默认值,否则如果没有原因,bot只会引发错误报告未在您发布的代码中定义,请确保您读取了json文件并获取了数据,否则可能会丢失一些数据
最后,解决方案
我想在你的代码中指出的一些事情是
相关问题 更多 >
编程相关推荐