ошибка музыкального бота дс
хай, делаю простенького музыкального бота для своего дс сервера, но происходит какая-то ошибка и не могу понять в чем дело
ошибка:
Traceback (most recent call last):
File "C:\Users\not_connor1\Desktop\PROJECTS\bot\venv\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\not_connor1\Desktop\PROJECTS\bot\music.py", line 25, in play
ctx.voice_bot.stop()
AttributeError: 'Context' object has no attribute 'voice_bot'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\not_connor1\Desktop\PROJECTS\bot\venv\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\not_connor1\Desktop\PROJECTS\bot\venv\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\not_connor1\Desktop\PROJECTS\bot\venv\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Context' object has no attribute 'voice_bot'
код: (1 - bot.py, 2- music.py)
import discord
from discord.ext import commands
import youtube_dl
class music(commands.Cog):
def __init__(self, bot):
self.bot = bot
@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_bot is None:
await voice_channel.connect
else:
await ctx.voice_bot.move_to(voice_channel)
@commands.command()
async def disconnect(self, ctx):
await ctx.voice_bot.disconnect()
@commands.command()
async def play(self, ctx, url):
ctx.voice_bot.stop()
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
YDL_OPTIONS = {'format':'bestaudio'}
vc = ctx.voice_bot
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_bot.pause()
await ctx.send('поставил на паузу!')
@commands.command()
async def resume(self, ctx):
await ctx.voice_bot.resume()
await ctx.send('убрал с паузы!')
def setup(bot):
bot.add_cog(music(bot))
import discord
import random
import music
from discord.ext import commands
cogs = [music]
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix='-', intents=intents)
for i in range(len(cogs)):
cogs[i].setup(bot)
bot.remove_command('help')
@bot.event
async def on_ready():
print('я тут!')
@bot.command(aliases = ['пинг'])
async def ping(ctx):
await ctx.send('pong!')
@bot.command( pass_context = True )
async def hello(ctx):
await ctx.send('даров,я yos bot!')
# chat
# words
hello_words = ['Hello', 'hi', 'хай', 'прив', 'дарова', 'сап', 'привет', 'хай', 'ку']
ask_words = ['инфо', 'информация', 'команды']
goodbye_words = ['пока', 'бб', 'досвидос', 'bye', 'bye', 'gg', 'гг']
#chat_messages
@bot.listen('on_message')
async def on_message(message):
msg = message.content.lower()
if msg in hello_words:
await message.channel.send('даров, чего хотел?')
if msg in ask_words:
await message.channel.send('инфу можно узнать по команде "-info"')
if msg in goodbye_words:
await message.channel.send('удачи и пока)')
# clear
#clear command
@bot.command (pass_context = True)
async def clear(ctx, amount=100):
await ctx.channel.purge(limit=amount)
#clear msg
async def clear_answer(ctx, amount = 1):
await ctx.channel.purge(limit=amount)
author = ctx.message.author
await ctx.send(f'Hello{author.mention}')
# help
@bot.command(pass_context = True)
async def help(ctx):
emb = discord.Embed(title='доступыне команды:')
emb.add_field(name='-clear', value='очистка чата')
emb.add_field(name='-randomize', value='сделает сложный выбор за тебя')
await ctx.send(embed=emb)
# randomize
@bot.command()
async def randomize(ctx):
import random
def check(m):
return m.author == ctx.author and m.channel == ctx.channel
msg = await ctx.send('напиши варианты через enter:')
args = await bot.wait_for('message', timeout=60, check=check)
args = args.content
args = args.split('\n')
random_choice = random.choice(args)
await msg.delete()
await ctx.send(f"и тебе выпадает {random_choice}!")
# connect
bot.run("ODkxNjk0NTYwNDcwNzY5NzA1.YVCFRg.lWNAoqgHvMSGBBTPeqdM3uqmknU")