python - 如何创建一个 2 字命令 discord.py?
问题描述
我想让机器人感知,例如,命令 .voice 打开,但给出错误
Command "voice" is not found
@commands.command(
name = "closevoice",
aliases = ["voice close"],
usage = "voice close",
)
async def voice_close(self, ctx):
pass
解决方案
你可以通过两种方式解决这个问题。
一种方法是创建一个命令“声音”,并将其作为参数打开和关闭。
@bot.command()
async def voice(self, ctx, arg1):
if arg1 == "open":
# DO SOMETHING
elif arg1 == "close":
# DO SOMETHING ELSE
或者,您可以让机器人监视消息并查找“语音打开”和“语音关闭”,而不是发出命令。
@bot.event
async def on_message(message):
if message.content == "voice open":
# DO SOMETHING
elif message.content == "voice close":
# DO SOMETHING ELSE
推荐阅读
- django - Django:在没有额外 SQL 的情况下获取外键字段的值到 DB
- sql - GROUP BY 影响 WHERE 子句
- vba - 选择了 0 个文件,但 VBA Excel 说我选择了 1 个文件
- android - Onclick 没有在 android 中调用 kitkat(4.4.4) 版本
- linux - 如何将 example.com 重定向到 example.com/xyz?
- javascript - 管理自定义 Highmap 中的投影
- java - 无法在 @ManyToOne 关系上插入空值
- twitter - 带有 Tweetmode.Extended 的空全文属性 [5 月 30 日更新]
- wordpress - HTML 标签字符“<”、“>”在自定义插件 wordpress 编辑器中转换为“<”、“>”
- rust - 如何使用具有关联类型的非静态特征对象?