在 discord.py 中是否可以对不同的前缀使用不同的命令?

is it possible to have different commands for different prefixes in discord.py?

是否可以为每个前缀设置不同的命令?例如,一个命令用于 !,另一个命令用于 ? 例如,某人执行 !foo 机器人响应 "foo",但另一个人执行 ?foo机器人响应 "bar"?

您可以创建一个带有两个前缀的机器人并创建一个 foo 命令。然后使用 ctx.prefix.

检查使用什么前缀调用命令
from discord.ext import commands

bot = commands.Bot(command_prefix=("!", "?"))


@bot.command()
async def foo(ctx):
    await ctx.send("foo" if ctx.prefix == "!" else "bar")

bot.run("TOKEN")

或者您可以使用 on_message 事件手动完成:

@bot.event
async def on_message(message):
    if message.content.lower() == "!foo":
        await message.channel.send("foo")
    elif message.content.lower() == "?foo":
        await message.channel.send("bar")
    await bot.process_commands(message)