Copy of Copy of 2Lazy4YouTube
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):
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:
- Go to the Discord Developer Portal:
-
Navigate to Discord Developer Portal.
-
Create a New Application:
- Click on New Application.
-
Give your application a name and click Create.
-
Create a Bot:
- In the left sidebar, click on Bot.
-
Click on Add Bot and confirm by clicking Yes, do it!.
-
Get the Bot Token:
- Under the TOKEN section, click Reset Token.
-
Copy the token provided.
-
Set the Environment Secret:
- In the Lazy Builder, go to the Environment Secrets tab.
-
Add a new secret with the key
DISCORD_BOT_TOKEN
and paste the token you copied. -
Enable Message Content Intent:
- 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:
- Invite the Bot to Your Server:
- Go to the OAuth2 section in the Discord Developer Portal.
- Under OAuth2 URL Generator, select the
bot
scope and the necessary permissions (e.g.,Connect
,Speak
,Send Messages
). - Copy the generated URL and open it in your browser.
-
Select the server you want to add the bot to and click Authorize.
-
Use the Bot Commands:
- 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!