Note
- PyLav assumes you are using PostgresSQL server running version 14, and it also requires Python3.11 any other version for these will not work/be supported.
- If you have docker; Setting up a postgres container for it would likely be the simplest option to set up the necessary server.
- If you have docker you can use the Lavalink v4 image instead of installing Java for more info see discord
Warning You should be using docker and using the provided docker-compose file for the easiest setup.
- A custom docker-compose file can be found here
- This uses a custom fork of Phasecore's redbot image to add support for python3.11 with PyLav bundled in i.e. docker-red-discordbot
- If using this setup make sure to use this pylav.yaml file for the PyLav config.
- Download the latest Lavalink v4 from the Lavalink Release
- Place these a directory of your choice.
- Edit the custom
application.yml(Deezer is disabled by default) to your liking changing theCHANGE_MEvalues, if you need help with this please join the Discord support server - Start an unmanaged Lavalink node using the
application.ymlyou just edited and theLavalink.jaryou just downloaded. - Make the following changes to your
pylav.yamlconfig file- Set
PYLAV__EXTERNAL_UNMANAGED_HOSTtolocalhost - Set
PYLAV__EXTERNAL_UNMANAGED_PASSWORDto thepasswordin thelavalink.serversection of theapplication.ymlfile - Set
PYLAV__EXTERNAL_UNMANAGED_PORTto theportin theserversection of theeapplication.ymlfile (Default is2154) - Set
PYLAV__EXTERNAL_UNMANAGED_SSLtofalse - Set
PYLAV__MANAGED_NODE_SPOTIFY_CLIENT_IDto theclientIdin theplugins.lavasrc.spotifysection of theapplication.ymlfile - Set
PYLAV__MANAGED_NODE_SPOTIFY_CLIENT_SECRETto theclientSecretin theplugins.lavasrc.spotifysection of theapplication.ymlfile - Set
PYLAV__MANAGED_NODE_SPOTIFY_COUNTRY_CODEto thecountryCodein theplugins.lavasrc.spotifysection of theapplication.ymlfile - Set
PYLAV__MANAGED_NODE_APPLE_MUSIC_API_KEYto themediaAPITokenin theplugins.lavasrc.applemusicsection of theapplication.ymlfile or if none leave it empty - Set
PYLAV__MANAGED_NODE_APPLE_MUSIC_COUNTRY_CODEto thecountryCodein theplugins.lavasrc.applemusicsection of theapplication.ymlfile - Set
PYLAV__MANAGED_NODE_YANDEX_MUSIC_ACCESS_TOKENto theaccessTokenin theplugins.lavasrc.yandexmusicsection of theapplication.ymlfile or if none leave it empty
- Set
If you are not on Ubuntu 20.04 you just have to follow the instructions below to install the dependencies and set them up for your Linux distro (Google is your friend).
-
sudo apt install libaio1 libaio-dev
-
- Follow the installation instruction here
- Note: When prompted to run
sudo apt-get -y install postgresqlmake sure to runsudo apt-get -y install postgresql-14instead. -
sudo -u postgres createuser -s -i -d -r -l -w <username>-sUser will be a superuser-iUser will inherit permissions from roles granted to it-dUser can create databases-rUser can create roles-lUser can log in-wUser will never be prompted for a password. If the server requires password authentication and a password is not available by other means, the connection attempt will fail.
sudo -u postgres psql -c "ALTER ROLE <username> WITH PASSWORD '<password>';"- Make sure to replace
<username>and<password>with the new values
- Make sure to replace
-
- Run
sudo -u postgres psql -c "CREATE DATABASE pylav_db;"- This will crete a new database called
pylav_db.
- This will crete a new database called
- Run
sudo -u postgres psql -c "ALTER DATABASE pylav_db OWNER TO <username>;"- This will set the owner of the database to the newly created user.
- Run
-
Enable PostgresSQL extensions (NOTICE - PyLav will do this for you if they are not enabled, however depending on your setup you may need to enable them manually)
- Run
sudo -u postgres psql -c "CREATE EXTENSION IF NOT EXISTS citext;" - Run
sudo -u postgres psql -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;" - Run
sudo -u postgres psql -c 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp";'
- Run
- Note: When prompted to run
- Follow the installation instruction here
-
- Follow the instructions here
- When prompted to run
sudo apt-get install zulu11-jdkmake sure to runsudo apt-get install zulu19-ca-jdk-headlessinstead.
- When prompted to run
- Follow the instructions here
-
- Follow the installation instruction here
-
- Open the
psqlcommand-line tool and login when prompted - Run
psql -u postgresto login as the userpostgres - When logged in run
CREATE ROLE <username> LOGIN PASSWORD '<password>';- Make sure to replace
<username>and<password>with the new values
- Make sure to replace
- Open the
-
- Run
CREATE DATABASE pylav_db;- This will crete a new database called
pylav_db.
- This will crete a new database called
- Run
ALTER DATABASE pylav_db OWNER TO <username>;- This will set the owner of the database to the newly created user.
- Run
-
Enable PostgresSQL extensions (NOTICE - PyLav will do this for you if they are not enabled, however depending on your setup you may need to enable them manually)
- Run
CREATE EXTENSION IF NOT EXISTS citext; - Run
CREATE EXTENSION IF NOT EXISTS pg_trgm; - Run
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
- Run
-
- Download and run the dmg executable here
-
- Follow the installation instruction here
-
- Open the
psqlcommand-line tool and login when prompted - Run
psql -u postgresto login as the userpostgres - When logged in run
CREATE ROLE <username> LOGIN PASSWORD '<password>';- Make sure to replace
<username>and<password>with the new values
- Make sure to replace
- Open the
-
- Run
CREATE DATABASE pylav_db;- This will crete a new database called
pylav_db.
- This will crete a new database called
- Run
ALTER DATABASE pylav_db OWNER TO <username>;- This will set the owner of the database to the newly created user.
- Run
-
Enable PostgresSQL extensions (NOTICE - PyLav will do this for you if they are not enabled, however depending on your setup you may need to enable them manually)
- Run
CREATE EXTENSION IF NOT EXISTS citext; - Run
CREATE EXTENSION IF NOT EXISTS pg_trgm; - Run
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
- Run
-
- Download and run the msi executable here
- Make sure to select the following when prompted
Add to PATH,set JAVA_HOME variableandJavaSoft (Oracle) registry keys
- Make sure to select the following when prompted
- Download and run the msi executable here
Note - All environment variables except PYLAV__LOGGER_PREFIX and PYLAV__YAML_CONFIG can be configured from the pylav.yaml file which should reside in the home directory of the user running the bot.
An example of the file can be found at pylav.example.yaml, if you don't create the file yourself pylav will do so on the first run.
PYLAV__YAML_CONFIG:- If you are in an environment where the home directory is not available you can specify a path to the config file using the
PYLAV__YAML_CONFIGenvironment variable. - This should be the absolute path to the
pylav.yamlfile i.e/config/pylav.yaml.
- If you are in an environment where the home directory is not available you can specify a path to the config file using the
PYLAV__LOGGER_PREFIX:- The prefix to use for the logger, defaults nothing, if provided all loggers used by PyLav will be prefixed with this value.
-
Go to your home directory for the user which will run the bot.
- Windows
- Run
cd %userprofile%
- Run
- Mac/Linux
- Run
cd ~
- Run
- Windows
-
Make a copy of
pylav.example.yamlto your home directory and name itpylav.yaml -
Change the values inside the
pylav.yamlto the desired values- Change
PYLAV__POSTGRES_PASSWORDfromchangemeto the password of the Postgres user you created above. - Change
PYLAV__POSTGRES_USERfromchangemeto the user you created above. - Change
PYLAV__POSTGRES_DBfrompylav_dbto the name of the database you created above (if you followed the commands above it should bepylav_db). - Change
PYLAV__POSTGRES_PORTandPYLAV__POSTGRES_HOSTto the connection host and port for the Postgres server. - To use a Unix socket instead of TCP
- Provide the
PYLAV__POSTGRES_SOCKETvariable. If this is providedPYLAV__POSTGRES_HOSTandPYLAV__POSTGRES_PORTwill be ignored. PYLAV__JAVA_EXECUTABLEcan be changed from java to the full path of the Azul Zulu 19 Java executable installed above.- By default, it will use
javato ensure you have the correct version underjavarunjava --versionif it says "OpenJDK Runtime Environment Zulu19..." then this is not needed to be changed.
- By default, it will use
- If you don't want PyLav to manage a node (not recommended) you can specify the connection args from an external node instead.
- Note: PyLav supports multiple bots running on the sam
- e machine, this should not be the reason why you set these.
- Set
PYLAV__EXTERNAL_UNMANAGED_HOSTto the Lavalink node connection host - Set
PYLAV__EXTERNAL_UNMANAGED_PASSWORDto the Lavalink node connection auth password. - Set
PYLAV__EXTERNAL_UNMANAGED_PORTto the Lavalink node connection port - If this is not specified the node will use port80ifPYLAV__EXTERNAL_UNMANAGED_SSLis set tofalseor443ifPYLAV__EXTERNAL_UNMANAGED_SSLis set totrue. - Set
PYLAV__EXTERNAL_UNMANAGED_SSLtotrueorfalsedepending on weather or not the external node is using SSL - Set
PYLAV__EXTERNAL_UNMANAGED_NAMEto the name of the external node (this is used for logging and event references)
- Set
- Change
-
If you already have a Redis server and want to make use of it for the request cache you can set
PYLAV__REDIS_FULL_ADDRESS_RESPONSE_CACHEto the full connection url of your existing server.- e.g.
redis://[[username]:[password]]@localhost:6379/0 - e.g.
unix://[[username]:[password]]@/path/to/socket.sock?db=0
- e.g.
-
If you want to change the frequency of Playlist update tasks you can change the values of the following, note it will only get applied for the next cycle.
PYLAV__TASK_TIMER_UPDATE_BUNDLED_PLAYLISTS_DAYS: Defaults to 1 # How many days to wait between updates - Minimum 1 Day.PYLAV__TASK_TIMER_UPDATE_BUNDLED_EXTERNAL_PLAYLISTS_DAYS: Defaults to 7 # How many days to wait between updates - Minimum 7 Days.PYLAV__TASK_TIMER_UPDATE_EXTERNAL_PLAYLISTS_DAYS: Defaults to 7 # How many days to wait between updates - Minimum 7 Days.
-
If you want PyLav to cache most of the queries from the Postgres server you can use
PYLAV__READ_CACHING_ENABLEDDO NOTE: If this is set to true multiple bots should not share the same database (The can still share the same Postgres server, just not the same database), as reads and writes will be out of sync.
- If this is turned off every read from the database will be a direct query to the database, if this is turned on PyLav will cache the results in memory after the first query.
- If you have a remote server, this will likely be a good idea to turn on, however you loose the ability to manually or otherwise edit the db and changes to be reflected in PyLav. - I would recommend enabling this ONLY if you notice slow operation with a remove Postgres server.
- If this is turned off every read from the database will be a direct query to the database, if this is turned on PyLav will cache the results in memory after the first query.
-
Optional configuration values
PYLAV__DEFAULT_SEARCH_SOURCE: Defaults to dzsearch - Possible values are dzsearch (Deezer), spsearch (Spotify), amsearch (Apple Music), ytmsearch (YouTube Music), ytsearch (YouTube)PYLAV__MANAGED_NODE_SPOTIFY_CLIENT_ID: Defaults to None - Required if you want to use Spotify with the managed nodePYLAV__MANAGED_NODE_SPOTIFY_CLIENT_SECRET: Defaults to None - Required if you want to use Spotify with the managed nodePYLAV__MANAGED_NODE_SPOTIFY_COUNTRY_CODE: Defaults to USPYLAV__MANAGED_NODE_APPLE_MUSIC_API_KEY- Defaults to NonePYLAV__MANAGED_NODE_APPLE_MUSIC_COUNTRY_CODE: Defaults to USPYLAV__MANAGED_NODE_YANDEX_MUSIC_ACCESS_TOKEN- Defaults to None - Required if you want to use Yandex with the managed nodePYLAV__MANAGED_NODE_DEEZER_KEY- Required if you want to use Deezer, leave empty unless you know what you are doing
- Make a copy of
pylav.docker.yamland mount it to any chosen path i.e./pylav.docker.yaml:/pylav/pylav.yaml - On your container set the following environment variables:
PYLAV__YAML_CONFIG=/pylav/pylav.yaml
- Change the values inside the
pylav.yamlto the desired valuesPYLAV__JAVA_EXECUTABLENot applicable leave it asjava, in a docket setup set the following environment variable instead:- Set
PYLAV__EXTERNAL_UNMANAGED_HOSTto the Lavalink node connection host - Set
PYLAV__EXTERNAL_UNMANAGED_PASSWORDto the Lavalink node connection auth password. - Set
PYLAV__EXTERNAL_UNMANAGED_PORTto the Lavalink node connection port - If this is not specified the node will use port80ifPYLAV__EXTERNAL_UNMANAGED_SSLis set tofalseor443ifPYLAV__EXTERNAL_UNMANAGED_SSLis set totrue. - Set
PYLAV__EXTERNAL_UNMANAGED_SSLtofalsedepending on weather or not the external node is using SSL
- If you already have a Redis server and want to make use of it for the request cache you can set
PYLAV__REDIS_FULL_ADDRESS_RESPONSE_CACHEto the full connection url of your existing server.- e.g.
redis://[[username]:[password]]@localhost:6379/0 - e.g.
unix://[[username]:[password]]@/path/to/socket.sock?db=0
- e.g.
- If you want to change the frequency of Playlist update tasks you can change the values of the following, note it will only get applied for the next cycle.
PYLAV__TASK_TIMER_UPDATE_BUNDLED_PLAYLISTS_DAYS: Defaults to 1 # How many days to wait between updates - Minimum 1 Day.PYLAV__TASK_TIMER_UPDATE_BUNDLED_EXTERNAL_PLAYLISTS_DAYS: Defaults to 7 # How many days to wait between updates - Minimum 7 Days.PYLAV__TASK_TIMER_UPDATE_EXTERNAL_PLAYLISTS_DAYS: Defaults to 7 # How many days to wait between updates - Minimum 7 Days.
- If you want PyLav to cache most of the queries from the Postgres server you can use
PYLAV__READ_CACHING_ENABLEDDO NOTE: If this is set to true multiple bots should not share the same database (The can still share the same Postgres server, just not the same database), as reads and writes will be out of sync.
- If this is turned off every read from the database will be a direct query to the database, if this is turned on PyLav will cache the results in memory after the first query.
- If you have a remote server, this will likely be a good idea to turn on, however you loose the ability to manually or otherwise edit the db and changes to be reflected in PyLav. - I would recommend enabling this ONLY if you notice slow operation with a remove Postgres server.
- If this is turned off every read from the database will be a direct query to the database, if this is turned on PyLav will cache the results in memory after the first query.
- Optional configuration values
PYLAV__DEFAULT_SEARCH_SOURCE: Defaults to dzsearch - Possible values are dzsearch (Deezer), spsearch (Spotify), amsearch (Apple Music), ytmsearch (YouTube Music), ytsearch (YouTube)PYLAV__MANAGED_NODE_SPOTIFY_CLIENT_ID: Defaults to None - Required if you want to use SpotifyPYLAV__MANAGED_NODE_SPOTIFY_CLIENT_SECRET: Defaults to None - Required if you want to use SpotifyPYLAV__MANAGED_NODE_SPOTIFY_COUNTRY_CODE: Defaults to USPYLAV__MANAGED_NODE_APPLE_MUSIC_API_KEY- Defaults to NonePYLAV__MANAGED_NODE_APPLE_MUSIC_COUNTRY_CODE: Defaults to USPYLAV__MANAGED_NODE_YANDEX_MUSIC_ACCESS_TOKEN- Defaults to None - Required if you want to use YandexPYLAV__MANAGED_NODE_DEEZER_KEY- Required if you want to use Deezer, leave empty unless you know what you are doingPYLAV__LOCAL_TRACKS_FOLDER- Defaults to a "music" folder created inside PyLav's data folderPYLAV__DATA_FOLDER- Default of an OS appropriate config folder
Install PyLav Cogs
- Now that you have your env fully setup you can process to installing the desired cogs.
[p]load downloader[p]repo add PyLav https://github.com/PyLav/Red-Cogs
- For a list of all available cogs visit the PyLav Cogs repo