Skip to content

Latest commit

 

History

History
267 lines (201 loc) · 6.46 KB

File metadata and controls

267 lines (201 loc) · 6.46 KB
title Development
description Set up your local development environment for Salada
**Prerequisites**: - Python 3.8 or higher - A running Lavalink server - Discord bot token and application

Follow these steps to set up your development environment and start building with Salada.

pip install salada

Download and configure your Lavalink server for development:

  1. Download the latest Lavalink.jar from GitHub releases
  2. Create an application.yml file:
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
  1. Start your Lavalink server:
java -jar Lavalink.jar

Set 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')

Environment Configuration

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=false

Then 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'))

Development Setup

Install additional development dependencies:

pip install python-dotenv
pip install aiohttp

Hot Reloading

For 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.py

Testing Your Setup

Create 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')

IDE Setup

We recommend using these extensions for the best development experience:

Visual Studio Code

  • Python - Official Python extension
  • Pylance - Fast Python language server
  • Python Type Hint - Type hint support
  • autopep8 or Black - Code formatting

PyCharm

  • Built-in Python support with type checking
  • Discord.py autocomplete
  • Integrated debugger

Configuration Files

Create these files in your project root:

pyproject.toml

[tool.black]
line-length = 100
target-version = ['py38']

[tool.isort]
profile = "black"
line_length = 100

requirements.txt

discord.py>=2.0.0
salada
python-dotenv
aiohttp

Troubleshooting

This usually means your Lavalink server isn't running or the connection details are incorrect.
1. 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
Your bot needs proper permissions to join voice channels.
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
This can happen when search sources aren't properly configured.
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
Salada requires Python 3.8 or higher for optimal performance.
1. Check your Python version: `python --version`
2. Update Python if needed
3. Reinstall dependencies: `pip install --upgrade salada`
Make sure all dependencies are properly installed.
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`

Development Best Practices

  • 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.