| title | Development |
|---|---|
| description | Set up your local development environment for Salada |
Follow these steps to set up your development environment and start building with Salada.
pip install saladaDownload and configure your Lavalink server for development:
- Download the latest Lavalink.jar from GitHub releases
- Create an
application.ymlfile:
server:
port: 2333
address: 0.0.0.0
lavalink:
server:
password: "youshallnotpass"
sources:
youtube: true
bandcamp: true
soundcloud: true
twitch: true
vimeo: true
http: true
local: false- Start your Lavalink server:
java -jar Lavalink.jarSet up your Discord bot with Salada:
import discord
from discord.ext import commands
from salada import Salad
INTENTS = discord.Intents.default()
INTENTS.message_content = True
INTENTS.voice_states = True
NODES = [{
'host': 'localhost',
'port': 2333,
'auth': 'youshallnotpass',
'ssl': False
}]
class MusicBot(commands.Bot):
def __init__(self):
super().__init__(command_prefix='!', intents=INTENTS)
self.salad = None
async def setup_hook(self):
self.salad = Salad(self, NODES)
await self.salad.start(NODES, str(self.user.id))
await self.tree.sync()
bot = MusicBot()
@bot.event
async def on_ready():
print(f'Bot is ready as {bot.user}')
bot.run('YOUR_BOT_TOKEN')Set up your environment variables for development:
# .env file
DISCORD_TOKEN=your_bot_token_here
LAVALINK_HOST=localhost
LAVALINK_PORT=2333
LAVALINK_AUTH=youshallnotpass
LAVALINK_SSL=falseThen load them in your application:
import os
from dotenv import load_dotenv
load_dotenv()
NODES = [{
'host': os.getenv('LAVALINK_HOST'),
'port': int(os.getenv('LAVALINK_PORT')),
'auth': os.getenv('LAVALINK_AUTH'),
'ssl': os.getenv('LAVALINK_SSL') == 'true'
}]
bot.run(os.getenv('DISCORD_TOKEN'))Install additional development dependencies:
pip install python-dotenv
pip install aiohttpFor faster development, use a tool like watchdog or run your bot with auto-restart:
pip install watchdog
watchmedo auto-restart --patterns="*.py" --recursive -- python bot.pyCreate a simple test command to verify everything is working:
from discord import app_commands
@bot.tree.command(name='test')
async def test(interaction: discord.Interaction):
await interaction.response.defer()
if not interaction.user.voice:
await interaction.followup.send('Join a voice channel first')
return
player = await bot.salad.createConnection({
'guildId': interaction.guild.id,
'textChannel': interaction.channel.id,
'voiceChannel': interaction.user.voice.channel.id
})
if player:
await interaction.followup.send('Salada connection successful')
else:
await interaction.followup.send('Failed to create player connection')We recommend using these extensions for the best development experience:
- Python - Official Python extension
- Pylance - Fast Python language server
- Python Type Hint - Type hint support
- autopep8 or Black - Code formatting
- Built-in Python support with type checking
- Discord.py autocomplete
- Integrated debugger
Create these files in your project root:
pyproject.toml
[tool.black]
line-length = 100
target-version = ['py38']
[tool.isort]
profile = "black"
line_length = 100requirements.txt
discord.py>=2.0.0
salada
python-dotenv
aiohttp1. Verify your Lavalink server is running: check `http://localhost:2333`
2. Check your `application.yml` configuration
3. Ensure the password matches in both files
4. Try restarting the Lavalink server
1. Ensure your bot has "Connect" and "Speak" permissions
2. Check if the voice channel isn't full or restricted
3. Verify the user is in a voice channel when creating the connection
1. Check your Lavalink `application.yml` sources configuration
2. Ensure YouTube and other sources are enabled (`true`)
3. Try different search terms or platforms
4. Check Lavalink logs for detailed error messages
1. Check your Python version: `python --version`
2. Update Python if needed
3. Reinstall dependencies: `pip install --upgrade salada`
1. Create a virtual environment: `python -m venv venv`
2. Activate it: `source venv/bin/activate` (Linux/Mac) or `venv\Scripts\activate` (Windows)
3. Install requirements: `pip install -r requirements.txt`
- Use virtual environments to isolate project dependencies
- Use environment variables for sensitive data like tokens
- Implement proper error handling for all Salada operations with try-except blocks
- Test with different audio sources to ensure compatibility
- Monitor Lavalink server logs during development
- Use type hints for better development experience and code clarity
- Follow PEP 8 style guidelines for clean, readable code
Ready to start building? Check out our API Reference for detailed documentation on all available methods and events.