本文介绍了命令大小写不敏感的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果成员上下或上下混合使用以下命令,如何使以下命令起作用。
如果成员使用 ping
,它将起作用。
,但如果成员使用 Ping
,则不起作用。
@ bot.event
异步定义on_message(message):
message.content = message.content.lower()
等待bot.process_commands(message)
@ bot.command(pass_context = True)
异步定义(ctx):
msg ='Pong {0.author.mention}'。format(ctx.message)
等待bot.say (msg)
更新:
以上
on_message
在单个文件中正常工作,但我将主文件拆分为多个文件。现在如何使它适用于所有文件中的齿轮。解决方案
您可以传递选项创建 Bot
。
从discord.ext导入命令
bot =命令.Bot('!',case_insensitive = True)
@ bot.command(pass_context = True)
异步def ping(ctx):
msg ='Pong {0.author.mention}'。format(ctx.message)
等待bot.say(msg)
How to make below command to work if members use below command in lower or upper or mixing.If members use ping
it works.but if members use Ping
it not works.
@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)
Update:
above on_message
is working correctly in single file but i splitted main file to multiple files. now how to make it work for cog in all files.
解决方案
You can pass a case_insensitive
option to your Bot
when you create it.
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)
这篇关于命令大小写不敏感的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!