Lukas Nesvarbu
Lukas Nesvarbu

Reputation: 11

Simple discord.py mp3 bot not playing music

Discord bot dosent play anykind of music, neither mine nor other bots codes work he just dosent play music. idk maybe i am just stupid BUT IT DOSENT WORK WHY

import discord
import time
import os
from discord.ext import commands

BOT_TOKEN = "" # put token here

intentss = discord.Intents.default()
intentss.message_content = True
intentss.voice_states = True

bot = commands.Bot(command_prefix=";;", intents = intentss)

OPUS_LIBS = ['libopus-0.x86.dll', 'libopus-0.x64.dll', 'libopus-0.dll', 'libopus.so.0', 'libopus.0.dylib']

@bot.command()
async def join(ctx):
    channelVC = ctx.author.voice.channel
    await channelVC.connect()

@bot.command()
async def leave(ctx):
    await ctx.voice_client.disconnect()

@bot.command()
async def play(ctx):
    voice = ctx.guild.voice_client
    mloc = 'C:/Users/Lukas/Desktop/Bot Bethoven/Youtube/test.mp3'
    voice.play(discord.FFmpegPCMAudio(executable = "C:/ffmpeg/bin/ffmpeg.exe", source = mloc))


bot.run(BOT_TOKEN)

it just give error codes:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ClientException: Not connected to voice.
INFO     discord.player ffmpeg process 22896 has not terminated. Waiting to terminate...
INFO     discord.player ffmpeg process 22896 should have terminated with a return code of 1.

intresting thing when i put join and play in the same command it dosent show not connected to voice error, actually it dosent show anything and neither plays mp3 file

i tryed reinstalling: PyNaCl, FFmpeg, Visual Code, updating python. nothing helps. this problem started after i did 1 month break from coding bot, before that it worked fine.

i'm thinking problem is something with my pc, maybe path or something dosent work(because it worked month ago and i didnt do anything to code), i tryed checking but everything seems normal,

Upvotes: 1

Views: 714

Answers (3)

DinO
DinO

Reputation: 1

Your problem is here:

channelVC = ctx.author.voice.channel

See with debug what is returning, should return a VocalGuildChannel object. But it dosen´t to be that case, so you have to secure what happens with "ctx.author.voice" because it is returning maybe None, secure that your profile is in a voice channel to be functional.

Upvotes: 0

DinO
DinO

Reputation: 1

I think that after the line:

voice.play(discord.FFmpegPCMAudio(executable = "C:/ffmpeg/bin/ffmpeg.exe", source = mloc))

Python finish the process, so cant execute properly the line, try to put this after

while voice.is_playing():
     await asyncio.sleep(1)
voice.disconnect()

Secondly, as I know with "ctx.guild.voice_client" which is a VoiceProtocol, you can´t use the methods of play(),pause() etc..., but firstly try with the lines that I said you, you should have a Exception of Attribute dosen´t exist.

Upvotes: 0

Lukas Nesvarbu
Lukas Nesvarbu

Reputation: 11

For me it was something with diffrent versions of python's i used, they did something to eatch other soo it just broke

fix for me was to DELETE everything asociated with Python (that includes modules) and reinstall it.

Upvotes: 0

Related Questions