【发布时间】:2021-07-19 04:35:24
【问题描述】:
您好,我需要有关警告命令的帮助。我不知道如何让它在聊天中说出这些东西,如果你告诉我如何解决这个问题,我最好希望它嵌入。
@bot.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 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)
break
else:
report['users'].append({
'name':user.name,
'reasons': [reason,]
})
with open('reports.json','w+') as f:
json.dump(report,f)
@bot.command(pass_context = True)
async def warnings(ctx,user:discord.User):
for current_user in report['users']:
if user.name == current_user['name']:
await ctx.send(f"```{user.name} has been reported {len(current_user['reasons'])} times : {','.join(current_user['reasons'])}```")
break
else:
await ctx.send(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 bot.send_message(ctx.message.channel, text)
【问题讨论】:
-
你是一个艰难的部分,逐字附加原因。只需这样做:
async def warn(ctx,user:discord.User,*, reason:str):这将在用户提及参数之后添加所有内容作为原因参数
标签: discord discord.py