Discord.py大写和小写

时间:2020-06-13 17:19:31

标签: python discord discord.py

我希望命令在字母为大写和小写时起作用,但是我不知道该怎么做。请帮我。例如:Ping PINg PiNg

@client.command()
async def ping(ctx):
    await ctx.send(f'Pong! ``{round(client.latency * 1000)}``')

1 个答案:

答案 0 :(得分:2)

您可以在实例化漫游器/客户端时指定不区分大小写:

client = commands.Bot(command_prefix="!", case_insensitive=True)

默认为false,但是将其设置为True将允许使用任意大小写的命令组合。

以及在on_message中创建命令时的等效内容:

if message.content.lower().startswith("!ping"):
    # do stuff

参考: