不和谐机器人 python 3.6 警告命令



我一直在研究一个版主不和谐机器人。发出除警告命令之外的所有命令。谁能帮我发出警告命令。

如果成员(具有管理成员权限(键入?warn @user reason机器人会将警告保存在 .json 文件中。

如果用户说?warnings @user机器人将显示用户的警告。

你可以做这样的事情

import discord
from discord.ext.commands import commands,has_permissions, MissingPermissions
import json
with open('reports.json', encoding='utf-8') as f:
try:
report = json.load(f)
except ValueError:
report = {}
report['users'] = []
client = discord.ext.commands.Bot(command_prefix = '?')
@client.command(pass_context = True)
@has_permissions(manage_roles=True, ban_members=True)
async def warn(ctx,user:discord.User,*reason:str):
if not reason:
await client.say("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)
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)
async def warnings(ctx,user:discord.User):
for current_user in report['users']:
if user.name == current_user['name']:
await client.say(f"{user.name} has been reported {len(current_user['reasons'])} times : {','.join(current_user['reasons'])}")
break
else:
await client.say(f"{user.name} has never been reported")  
@warn.error
async def kick_error(error, ctx):
if isinstance(error, MissingPermissions):
text = "Sorry {}, you do not have permissions to do that!".format(ctx.message.author)
await client.send_message(ctx.message.channel, text)   
client.run("BOT_TOKEN")

您可以将所有用户的报告保存在名为reports.json的文件中,而不是manage_roles=True, ban_members=True保存在@has_permissions里面,您可以放置文档中的任何内容

最新更新