A
A
Abiba2282022-02-10 17:36:04
Python
Abiba228, 2022-02-10 17:36:04

Play command error what to do?

import os
import asyncio
import youtube_dl
import discord
import datetime
import json
import requests
import random
from discord.ext import commands
from discord_slash import SlashCommand

Bot = commands.Bot(command_prefix="c:", intents=discord.Intents.all())
slash = SlashCommand(Bot, sync_commands=True)
Bot.remove_command('help')

@slash.slash()
async def play(ctx, url : str):
    song_there = os.path.isfile('song.mp3')

    try:
        if song_there:
            os.remove('song.mp3')
            print('[log] Старий файл удален')
    except PermissionError:
        print('[log] Не удалось удалить файл')

    await ctx.send('пожалуста ожидайте')

    voice = get(client.voice_clients, guild = ctx.guild)

    ydl_opts ={
        'format' : 'bestaudio/best',
        'postprocessors' : [{
            'key' : 'FFmpegExtractAudio',
            'preferredcodec' : 'mp3',
            'preferredquality' : '192'
        }],
    }

    with youtube_dl.YoutubeDL(ydl_opts) as ydl :
        print('[log] Загружаю Музику...')
        ydl.download([url])

    for file in os.listdir('./'):
        if file.endswith('.webm'):
            name = file
            print('[log] переименовиваю файл {file}')
            os.rename(file, 'song.mp3')

    voice.play(discord.FFmpegPCMAudio('song.mp3'), after = lambda e: print(f'[log] {name}, музика закончилась'))
    voice.sourse = discord.PCMVolumeTransformer(voice.sourse)
    voice.sourse.volume = 0.07

    song_name = name.rsplist('-', 2)
    await ctx.send(f'Сейчас проигривает музика: {song_name[0]}')


Gives an error message.

An exception has occurred while executing command 'play': Traceback (most recent call last):

File "C:\Users\ilbaa\AppData\Local\Programs\Python\Python36\lib\site-packages\discord_slash\client.py" , line 1353, in invoke_command await func.invoke(ctx, **args)

File "C:\Users\ilbaa\AppData\Local\Programs\Python\Python36\lib\site-packages\discord_slash\model.py", line 210, in invoke return await self.func(*args, **kwargs)

File "C:\Users\ilbaa\Desktop\Monika.py", line 41, in play voice = get(client.voice_clients, guild = ctx. guild)

NameError: name 'get' is not defined

An exception has occurred while executing command 'play': Traceback (most recent call last):

File "C:\Users\ilbaa\AppData\Local\Programs\Python\Python36\lib\site-packages\discord_slash\client.py", line 1353, in invoke_command await func.invoke(ctx, **args)

File " C:\Users\ilbaa\AppData\Local\Programs\Python\Python36\lib\site-packages\discord_slash\model.py", line 210, in invoke return await self.func(*args, **kwargs)

File" C:\Users\ilbaa\Desktop\Monika.py", line 41, in play

voice = get(client.voice_clients, guild = ctx.guild)

NameError: name 'get' is not defined

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question