Untitled

mail@pastecode.io avatar
unknown
javascript
7 months ago
1.3 kB
1
Indexable
Never
import discord
from discord.ext import commands
from discord.ext.commands import Bot

import youtube_dl

bot = commands.Bot(command_prefix='!')

@bot.event
async def on_ready():
    print(f'Bot is ready: {bot.user.name}')

@bot.command(name='join', help='Botu ses kanalına davet eder')
async def join(ctx):
    channel = ctx.author.voice.channel
    await channel.connect()

@bot.command(name='leave', help='Botu ses kanalından çıkarır')
async def leave(ctx):
    await ctx.voice_client.disconnect()

@bot.command(name='play', help='Belirtilen YouTube videosunu çalar')
async def play(ctx, url):
    ydl_opts = {'format': 'bestaudio'}
    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
        info = ydl.extract_info(url, download=False)
        url2 = info['formats'][0]['url']
        voice_channel = ctx.author.voice.channel
        voice_channel.connect()
        voice_channel.play(discord.FFmpegPCMAudio(url2), after=lambda e: print(f'Error: {e}') if e else None)

@bot.command(name='pause', help='Müziği duraklatır')
async def pause(ctx):
    ctx.voice_client.pause()

@bot.command(name='resume', help='Duraklatılmış müziği devam ettirir')
async def resume(ctx):
    ctx.voice_client.resume()

@bot.command(name='stop', help='Müziği durdurur')
async def stop(ctx):
    ctx.voice_client.stop()

bot.run('YOUR_BOT_TOKEN')
Leave a Comment