Is the a way to use prefix AND ping for commands?

泪湿孤枕 提交于 2020-01-30 11:39:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!