问题
I've decided to create a much more helpful bot, and I would like to allow the commands to be activated in two ways: x.
which is the default prefix and @xubot
, aka pinging the bot.
My commands are set out like this:
# sidenote: this is not an actual command ;)
pref = 'x.'
client = Bot(command_prefix=pref)
@client.command(name="example",
pass_ctx=True)
async def example(ctx, type=""):
# the "type" parameter is used so i can check if it is "help" and display an embed
await ctx.send("Test!")
However, I can only activate the commands with my prefix, x.
I would like for @xubot example
to run the command, as well as x.example
. Is there a way to achieve this?
回答1:
Pass the commands.when_mentioned_or function as your prefix:
from discord.ext.commands import Bot, when_mentioned_or
bot = Bot(command_prefix=when_mentioned_or("x."))
...
来源:https://stackoverflow.com/questions/56481969/is-the-a-way-to-use-prefix-and-ping-for-commands