python - 命令大小写不敏感
问题描述
如果成员在下部或上部或混合中使用以下命令,如何使以下命令起作用。如果会员使用ping
它就可以了。但如果成员使用Ping
它不起作用。
@bot.event
async def on_message(message):
message.content = message.content.lower()
await bot.process_commands(message)
@bot.command(pass_context=True)
async def ping(ctx):
msg = 'Pong {0.author.mention}'.format(ctx.message)
await bot.say(msg)
更新:
以上on_message
在单个文件中正常工作,但我将主文件拆分为多个文件。现在如何使它适用于所有文件中的 cog。
解决方案
您可以在创建选项时将case_insensitive
选项传递给您的选项Bot
。
from discord.ext import commands
bot = commands.Bot('!', case_insensitive=True)
@bot.command(pass_context=True)
async def ping(ctx):
msg = 'Pong {0.author.mention}'.format(ctx.message)
await bot.say(msg)
推荐阅读
- apache-spark - 如何在 Spark 结构化流中指定 deltalake 表的位置?
- openedge - 如何使用按钮更改浏览窗口的大小?
- r - 过滤行数大于列数的*n矩阵
- google-apps-script - 通过 google.script.run 上传文件
- azure - Azure 网站文件上传文件未找到异常
- sql - 根据组中值对的条件选择行
- angular - 使用 Angular 在 Azure Maps 中绘制一条线
- javascript - Fabricjs:画布内存使用超过iPad中的最大限制
- c# - Angular6 POST 请求仍处于待处理状态
- reactjs - 为什么我需要为反应原生应用安装 npm