python - discord.py 中的条件命令
问题描述
我希望用户能够通过例如说 !ask [___] 之类的话来了解某事。我会有一份它可能会问的事情的清单。具体来说,特定音阶中的音符。所以他们会问 !scale Cmajor 并得到“C 大调中的音符是 C、D、E、F、G、A、B”的响应。我是一个绝对的初学者,不知道如何做到这一点。我以前做过一个机器人,但这就是我所有的 python 经验。
解决方案
您可以从 discord.py文档中查看如何执行此类任务
具体来说,假设您使用的是最新版本的 discord.py 并遵循适当的设置,这样的事情可能会起作用:
# This is assuming your prefix is already defined, and you have a general bot setup
@bot.command()
async def scale(ctx, arg): # assuming the prefix is !, the command will be !scale argument
if arg.lower() == "cmajor":
await ctx.send("The notes in C major are C,D,E,F,G,A,B.")
else:
await ctx.send("Invalid scale.") # add more scales as needed
推荐阅读
- java - 如何使用 ExtractorMediaSource.Factory 在 ExoPlayer 中设置自定义标头?
- scala - 强制 Apache Flink 在给定点执行
- python - 在 Pandas 中合并索引上的数据帧更有效
- excel - 设置 Excel 网格线 VB.net
- java - object==object,不比较参考
- asp.net-web-api - 查询参数 web api 上的自定义验证属性
- angular - Angular 6 手表数据从第 3 次服务更改
- batch-file - 使用 XCOPY 获取复制文件的数量
- beacon - Android Eddystone - URL Chrome 物理网络
- java - 新的 cassandra 绑定语句 getDate 方法