discord - 警告命令
问题描述
您好,我需要有关警告命令的帮助。我不知道如何让它在聊天中说出这些东西,如果你告诉我如何解决这个问题,我最好希望它嵌入。
@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)
解决方案
用于并嵌入代码。例如:
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}")
我不确定这是否可行,但您可以尝试
推荐阅读
- reactjs - 使用一个按钮保存来自表单和另一个组件的数据
- c# - CS0103。当前上下文中不存在名称“函数”
- gnuradio - GNU Radio 标准块的内部结构
- c++ - 如何在 Visual Studio 的同一 C++ 解决方案中正确地将 dll 项目链接到另一个项目?
- swift - Swift:无法将任何视图的返回表达式转换为某个视图的返回类型
- firebase - Firestore Web 客户端不指向模拟器 - 抛出 PERMISSION_DENIED:缺少权限或权限不足
- c++ - 如何手动销毁 C++ 对象?
- swift - 对拖动视图做出反应
- caching - Redis CRDB 驱逐策略
- android - Android Studio 仅在选择 Build APK 而不是单击 Run 按钮时对 APK 进行签名