python - 如何在命令中激活命令 (discord.py)
问题描述
我想做的是让机器人在“帮助”命令列表下对命令做出响应
@bot.command(pass_context = True)
async def help(ctx):
a_embed1 = discord.Embed(title="Vibe's Command List")
a_embed1.add_field(name=':smile: Fun', value="`vb help fun`", inline=True)
await ctx.send(embed=a_embed1)
就像当我输入“ prefix_here help Economy”时,将发送经济嵌入列表而不是帮助嵌入列表。任何帮助将非常感激!
解决方案
添加一个参数并将其默认为 None 然后检查它是否不是 None 然后发送通用帮助命令 否则使用 if-elifs 检查它等于什么并发送它的帮助
@bot.command()
async def help(ctx, c=None):
if not c: # normal help command
a_embed1 = discord.Embed(title="Vibe's Command List")
a_embed1.add_field(name=':smile: Fun', value="`vb help fun`", inline=True)
await ctx.send(embed=a_embed1)
elif c.lower() == "economy":
# define embed and send
# multiple elifs for other commands
推荐阅读
- python - Django 关系“users_driverregistration”不存在
- erlang - 带有 ED25519 证书文件的 Erlang TLS
- python - python: pandas + fpdf + double groupby
- python - 为什么它打印会话 id 而不是元素路径?
- javascript - 我的 venobox jQuery 视频帧未加载
- ios - UIView isFocused 与 isFirstResponder
- traveling-salesman - 具有多次行程的 OR-Tools CVRP
- hashicorp-vault - 如何编写允许在 Hashicorp Vault 中删除策略的策略
- java - 带有数据提供者的 JUnit TestNG,其中包括一个匿名函数
- reactjs - React,Material-UI - onClick() 总是将最后一项作为参数