> ## Documentation Index
> Fetch the complete documentation index at: https://salad-ffed6391.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Development

> Set up your local development environment for Salada

<Info>
  **Prerequisites**:

  * Python 3.8 or higher
  * A running Lavalink server
  * Discord bot token and application
</Info>

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

<Steps>
  <Step title="Install Salada">
    ```bash theme={null}
    pip install salada
    ```
  </Step>

  <Step title="Set up Lavalink server">
    Download and configure your Lavalink server for development:

    1. Download the latest Lavalink.jar from [GitHub releases](https://github.com/lavalink-devs/Lavalink/releases)
    2. Create an `application.yml` file:

    ```yaml theme={null}
    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
    ```

    3. Start your Lavalink server:

    ```bash theme={null}
    java -jar Lavalink.jar
    ```
  </Step>

  <Step title="Create your bot">
    Set up your Discord bot with Salada:

    ```python theme={null}
    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')
    ```
  </Step>
</Steps>

## Environment Configuration

Set up your environment variables for development:

```bash theme={null}
# .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:

```python theme={null}
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:

```bash theme={null}
pip install python-dotenv
pip install aiohttp
```

## Hot Reloading

For faster development, use a tool like `watchdog` or run your bot with auto-restart:

```bash theme={null}
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:

```python theme={null}
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**

```toml theme={null}
[tool.black]
line-length = 100
target-version = ['py38']

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

**requirements.txt**

```txt theme={null}
discord.py>=2.0.0
salada
python-dotenv
aiohttp
```

## Troubleshooting

<AccordionGroup>
  <Accordion title="Error: Cannot connect to Lavalink server">
    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
  </Accordion>

  <Accordion title="Error: Missing Access - connect to voice channel">
    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
  </Accordion>

  <Accordion title="Error: No tracks found">
    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
  </Accordion>

  <Accordion title="Python version compatibility">
    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`
  </Accordion>

  <Accordion title="AttributeError or import errors">
    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`
  </Accordion>
</AccordionGroup>

## 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](https://github.com/ToddyTheNoobDud/Salad/blob/main/examples/music.py) for detailed documentation on all available methods and events.
