C
C
calvin372021-08-11 09:24:02
Python
calvin37, 2021-08-11 09:24:02

Why does Discord Music Bot give an error and how to fix it?

Hello everyone, it gives an error, I do not understand what the problem is.
Code 1st part:

import discord
from discord.ext import commands
import music

cogs = [music]

client = commands.Bot(command_prefix='?', intents = discord.Intents.all())

for i in range(len(cogs)):
    cogs[i].setup(client)

client.run("ODc0ODkxNTE2NDU4NDQ2ODY5.YRNkOA.Jf_2ArgH99e0jlJTEFywBJmNx-4")


Code 2nd part:

import discord
from discord.ext import commands
import youtube_dl

class music(commands.Cog):
    def __init__(self, client):
        self.client = client

    @commands.command()
    async def join(self, ctx):
        if ctx.author.voice is None:
            await ctx.send('Ты не в голосовом канале!')
        voice_channel = ctx.author.voice.channel
        if ctx.voice_client is None:
            await voice_channel.connect()
        else:
            await ctx.voice_client.move_to(voice_channel)

    @commands.command()
    async def disconnect(self, ctx):
         await ctx.voice_client.disconnect()

    @commands.command()
    async def play(self, ctx, url):
        ctx.voice_client.stop()
        FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
        YDL_OPTIONS = {'format':"bestaudio"}
        vc = ctx.voice_client

        with youtube_dl.YoutubeDL(YDL_OPTIONS) as ydl:
            info = ydl.extract_info(url, download=False)
            url2 = info['formats'][0]['url']
            source = await discord.FFmpegOpusAudio.from_probe(url2, **FFMPEG_OPTIONS)
            vc.play(source)

    @commands.command()
    async def pause(self, ctx):
        await ctx.voice_client.pause()
        await ctx.send('Пауза')

    @commands.command()
    async def resume(self, ctx):
        await ctx.voice_client.resume()
        await ctx.send('Снять с паузы')

def setup(client):
        client.add_cog(music(client))


Screenshot error:

61136ceca3b23307385668.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
Zef1rok, 2021-08-11
@calvin37

61136e4ce6ca8061592437.png
pay attention to this
https://discordpy.readthedocs.io/en/stable/api.htm...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question