O
O
old_stalin2020-09-27 23:36:36
Python
old_stalin, 2020-09-27 23:36:36

Is it possible to make 2 different prefixes?

I want to make it accept 2 prefixes from me, but through different commands, that is:
bot1 = commands.Bot(command_prefix=['.'])
client = commands.Bot(command_prefix=settings['prefix'])

I do this and it just doesn't accept
@bot1.command()
async def ...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Nevzorov, 2020-09-28
@old_stalin

command_prefixYou can use the function as an argument value :
Bot.command_prefix

The command prefix is ​​what the message content must contain initially to have a command invoked. This prefix could either be a string to indicate what the prefix should be, or a callable that takes in the bot as its first parameter and discord.Message as its second parameter and returns the prefix. This is to facilitate “dynamic” command prefixes. This callable can be either a regular function or a coroutine.

You can create a function that will return a prefix depending on the content of the message:
SPECIAL_PREFIX = "."


def context_prefix(bot, message):
    special_command = bot.get_command("choose")
    if any(
        message.content.startswith(f"{SPECIAL_PREFIX}{command_string}")
        for command_string in [special_command.name, *special_command.aliases]
    ):
        return SPECIAL_PREFIX
    return "&"


bot = commands.Bot(command_prefix=context_prefix)

Thus, the command choosewill be called with the prefix ., while the rest with the prefix &:53Be2Ag.png

S
soremix, 2020-09-27
@SoreMix

Well, enter the prefix you need in the first initialization

bot1 = commands.Bot(command_prefix=['.', settings[‘prefix’]])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question