Example #1
0
    async def change_prefix(self, ctx, prefix: CheckLength.check_length):
        """Changes server's command prefix

        :param ctx: the context in which a command is called
        :type ctx: discord.ext.commands.Context
        :param prefix: new prefix which invokes commands
        :type prefix: str
        """
        old_prefix = \
            Database.get_one(Database.db_servers, {'_id': ctx.guild.id}, selection={'settings.prefix': 1, '_id': 0})[
                'settings']['prefix']
        # Zapytanie w MongoDB, aby wejsc glebiej do slownika po kluczach uzywamy '.'
        if Database.update_one(Database.db_servers, {'_id': ctx.guild.id}, {'settings.prefix': prefix}):
            await ctx.send(f'Pomyślnie zmienio prefix z {old_prefix} na {prefix}')
Example #2
0
    def get_server_prefix(bot, message):
        """Gets server id from sent message

        :param bot: instance of Bot
        :type bot: discord.ext.commands.bot.Bot
        :param message: contains information about message
        :type message: discord.Message
        :return: server's prefix
        :rtype: str
        """

        prefix = None
        try:
            prefix = Database.get_one(Database.db_servers, {'_id': message.guild.id})['settings']['prefix']
        except:
            pass

        if prefix is None:
            return default_prefix
        return prefix