Copy of Copy of 2Lazy4YouTube

Start with this template
15
import discord
from discord import app_commands
import os
import yt_dlp
import discord.opus
from discord.ext import commands
import asyncio

intents = discord.Intents.default()
intents.messages = True
intents.message_content = True

bot = commands.Bot(command_prefix='/', intents=intents)
bot_token = os.environ.get('DISCORD_BOT_TOKEN')

@bot.event
async def on_ready():
    print(f'Logged in as {bot.user.name}')
    await bot.tree.sync()
    await bot.change_presence(activity=discord.CustomActivity("Waiting for music to play 🙂"))

async def get_interaction(guild):
    class DummyInteraction:
        def __init__(self, guild):
Get full code

Copy of Copy of 2Lazy4YouTube

Created: | Last Updated:

Introduction to the Template

Welcome to the "Copy of Copy of 2Lazy4YouTube" template! This template helps you create a Discord bot that streams music from YouTube directly into your Discord server. The bot can play music, change volume, and stop music based on user commands.

Getting Started

To get started with this template, click Start with this Template.

Initial Setup

This template requires you to set up an environment secret for the bot token. Follow these steps to obtain and set up your Discord bot token:

  1. Go to the Discord Developer Portal:
  2. Navigate to Discord Developer Portal.

  3. Create a New Application:

  4. Click on New Application.
  5. Give your application a name and click Create.

  6. Create a Bot:

  7. In the left sidebar, click on Bot.
  8. Click on Add Bot and confirm by clicking Yes, do it!.

  9. Get the Bot Token:

  10. Under the TOKEN section, click Reset Token.
  11. Copy the token provided.

  12. Set the Environment Secret:

  13. In the Lazy Builder, go to the Environment Secrets tab.
  14. Add a new secret with the key DISCORD_BOT_TOKEN and paste the token you copied.

  15. Enable Message Content Intent:

  16. Under the Privileged Gateway Intents section, enable the Message Content Intent.

Test

Press the Test button to deploy the app. The Lazy CLI will handle the deployment process.

Entering Input

After pressing the Test button, you will be prompted to provide the following user input through the Lazy CLI:

  • YouTube URL: The URL of the YouTube video or livestream you want to play.
  • Volume Percentage: The volume level (0-100) at which you want the audio to play.

Using the App

Once the bot is deployed and running, you can use the following commands in your Discord server:

  • /play_music: Plays audio from a YouTube URL in a voice channel.
  • Parameters:

    • url: The YouTube URL of the video or livestream to play.
    • volume_percentage: The volume to play the audio at (0-100).
  • /change_volume: Changes the volume of the currently playing audio.

  • Parameters:

    • volume_percentage: The new volume to set (0-100).
  • /stop_music: Stops the currently playing audio.

Integrating the App

To integrate the bot into your Discord server, follow these steps:

  1. Invite the Bot to Your Server:
  2. Go to the OAuth2 section in the Discord Developer Portal.
  3. Under OAuth2 URL Generator, select the bot scope and the necessary permissions (e.g., Connect, Speak, Send Messages).
  4. Copy the generated URL and open it in your browser.
  5. Select the server you want to add the bot to and click Authorize.

  6. Use the Bot Commands:

  7. In your Discord server, use the commands /play_music, /change_volume, and /stop_music to control the bot.

By following these steps, you will have a fully functional Discord bot that streams music from YouTube into your server. Enjoy your music experience!

Technologies

Python Python
Discord Discord