serenity
serenity copied to clipboard
[StandardFramework] dynamic_prefix called before other conditions are considered
Within the StandardFramework, the prefix is acquired very early. This can add extra overhead, since with dynamic_prefix, it may be necessary to query a file or database to get the prefix.
It may be advisable to check other conditions on the message before acquiring the prefix, particularly if it is dynamic. For example, bots using the StandardFramework configured to ignore_bots(true)
will still call the dynamic_prefix function when they receive a message from a bot.
Within a Python bot where I used my own on_message handler, matching a regex across message content has been effective at pushing back grabbing the prefix until absolutely necessary:
command_name_and_aliases = 'help|info|play|stop'
match_string =
r'(?:(?:<@ID>\s+)|(?:<@!ID>\s+)|(?P<prefix>\S+?))(?P<cmd>COMMANDS)(?:$|\s+(?P<args>.*))' \
.replace('ID', str(user_id)).replace('COMMANDS', command_names_and_aliases)
This gets the prefix in the message and then it is later compared with the prefix the bot uses to check if it is a valid command call