警告命令

时间:2021-04-25 16:42:47

标签: discord discord.py

您好,我需要有关警告命令的帮助。我不知道如何让它说出聊天中的内容,如果你确实告诉我如何解决这个问题,我最好将其嵌入。

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

1 个答案:

答案 0 :(得分:0)

for 和嵌入代码。例如:

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}")

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