首页 > 解决方案 > 警告命令

问题描述

您好,我需要有关警告命令的帮助。我不知道如何让它在聊天中说出这些东西,如果你告诉我如何解决这个问题,我最好希望它嵌入。

@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)   

标签: discorddiscord.py

解决方案


用于并嵌入代码。例如:

embed = discord.Embed(title=f'{member}\'s Warning!',color=0x1d9521)
    embed.add_field(name='why he is warned',value=reason, inline=False)    
    embed.add_field(name="Moderator that warned", value={ctx.author.mention}, inline=False)

我不确定这是否可行,但随后发送即可

   await ctx.send(embed=embed)

另一种发送方式是

await ctx.reply(embed=embed)

把这个从嵌入中去掉,你可以做

await ctx.send("Why they are warned    `{reason}`/nThe Responsible Moderator   {ctx.author.mention}")

我不确定这是否可行,但您可以尝试


推荐阅读