justdraxs

you need to make a bot that when you do /download menu it downloads what i have put in it

Kodari AI
KodariApr 28 at 6:46 pm 2,596 (v2)

I’ll create a Discord bot with a /download menu slash command that displays a configurable list of downloadable files via a select dropdown menu.

DownloadMenuBot
A Discord bot that provides a `/download menu` slash command, displaying a stylish embed with a dropdown select menu of downloadable files. Admins can add, remove, and list download entries using `/download add`, `/download remove`, and `/download list`. Each entry stores a name, description, and URL. Selecting an item from the menu sends the user an ephemeral message with the download link.

Here’s how the bot works:

User commands:

  • /download menu — Shows an embed with a dropdown. Selecting a file sends you an ephemeral message with the download link.

Admin commands (requires Administrator permission):

  • /download add <name> <url> [description] — Adds a new file to the menu

  • /download remove <name> — Removes a file from the menu

  • /download list — Lists all current entries

Setup:

  1. Replace your_discord_bot_token_here in .env with your bot token

  2. Install deps: pip install -r requirements.txt

  3. Run: python bot.py

⚠️ Make sure your bot has the applications.commands scope enabled in the Discord Developer Portal when generating your invite link.

Kodari can make mistakes. Review important code before using.
Files
bot.py
downloads.json
requirements.txt
Code
3 134
bot.py
import discord
from discord.ext import commands
from discord import app_commands
import os
import json
from dotenv import load_dotenv

load_dotenv()

DOWNLOADS_FILE = "downloads.json"

def load_downloads():
    with open(DOWNLOADS_FILE, "r") as f:
        return json.load(f)

def save_downloads(data):
    with open(DOWNLOADS_FILE, "w") as f:
        json.dump(data, f, indent=2)

intents = discord.Intents.default()
bot = commands.Bot(command_prefix="!", intents=intents)
tree = bot.tree

class DownloadSelect(discord.ui.Select):
    def __init__(self, downloads):
        options = [
            discord.SelectOption(
                label=item["name"][:100],
                description=item["description"][:100] if item.get("description") else None,
                value=str(i)
            )
            for i, item in enumerate(downloads)
        ]
        super().__init__(placeholder="Choose a file to download...", options=options)
        self.downloads = downloads

    async def callback(self, interaction: discord.Interaction):
        item = self.downloads[int(self.values[0])]
        embed = discord.Embed(
            title=f"⬇️ {item['name']}",
            description=item.get("description", ""),
            color=discord.Color.green()
        )
        embed.add_field(name="Download Link", value=item["url"], inline=False)
        await interaction.response.send_message(embed=embed, ephemeral=True)

class DownloadView(discord.ui.View):
    def __init__(self, downloads):
        super().__init__(timeout=60)
        self.add_item(DownloadSelect(downloads))

download_group = app_commands.Group(name="download", description="Download menu commands")

@download_group.command(name="menu", description="Browse and download available files")
async def download_menu(interaction: discord.Interaction):
    downloads = load_downloads()
    if not downloads:
        await interaction.response.send_message(
            "❌ No downloads have been added yet.", ephemeral=True
        )
        return

    embed = discord.Embed(
        title="📦 Download Menu",
        description="Select a file from the dropdown below to get its download link.",
        color=discord.Color.blurple()
    )
    embed.set_footer(text=f"{len(downloads)} file(s) available")
    view = DownloadView(downloads)
    await interaction.response.send_message(embed=embed, view=view)

@download_group.command(name="add", description="Add a new download entry (Admin only)")
@app_commands.describe(name="Display name of the file", url="Direct download URL", description="Short description of the file")
@app_commands.default_permissions(administrator=True)
async def download_add(interaction: discord.Interaction, name: str, url: str, description: str = ""):
    downloads = load_downloads()
    for item in downloads:
        if item["name"].lower() == name.lower():
            await interaction.response.send_message(
                f"❌ An entry named **{name}** already exists.", ephemeral=True
            )
            return

    downloads.append({"name": name, "url": url, "description": description})
    save_downloads(downloads)
    await interaction.response.send_message(
        f"✅ Added **{name}** to the download menu.", ephemeral=True
    )

@download_group.command(name="remove", description="Remove a download entry (Admin only)")
@app_commands.describe(name="Name of the entry to remove")
@app_commands.default_permissions(administrator=True)
async def download_remove(interaction: discord.Interaction, name: str):
    downloads = load_downloads()
    updated = [item for item in downloads if item["name"].lower() != name.lower()]
    if len(updated) == len(downloads):
        await interaction.response.send_message(
            f"❌ No entry named **{name}** found.", ephemeral=True
        )
        return

    save_downloads(updated)
    await interaction.response.send_message(
        f"✅ Removed **{name}** from the download menu.", ephemeral=True
    )

@download_group.command(name="list", description="List all download entries (Admin only)")
@app_commands.default_permissions(administrator=True)
async def download_list(interaction: discord.Interaction):
    downloads = load_downloads()
    if not downloads:
        await interaction.response.send_message("📭 No downloads added yet.", ephemeral=True)
        return

    embed = discord.Embed(title="📋 All Download Entries", color=discord.Color.blurple())
    for i, item in enumerate(downloads, 1):
        embed.add_field(
            name=f"{i}. {item['name']}",
            value=f"**URL:** {item['url']}\n**Desc:** {item.get('description') or 'None'}",
            inline=False
        )
    await interaction.response.send_message(embed=embed, ephemeral=True)

tree.add_command(download_group)

@bot.event
async def on_ready():
    await tree.sync()
    print(f"✅ Logged in as {bot.user} | Slash commands synced")

bot.run(os.getenv("DISCORD_TOKEN"))