1
votes

So I want to play local files in my discord voice channel, right now it joins the voice channel but it does not play anything. This is the code:

if message.content.startswith('$Hest'):
    where = message.content.split(" ")[1]
    channel = get(message.guild.channels, name=where)
    voicechannel = await channel.connect()
    voicechannel.play(discord.FFempegPCMAudio(executable='D:/ffmpeg/ffmpeg/bin/ffplay.exe', source='D:/ffmpeg/Horse.mp3'))

And this is my output when I try to do it

Traceback (most recent call last):
  File "F:\Apanda\CustomMultiPyBot\venv\lib\site-packages\discord\client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "F:/Apanda/CustomMultiPyBot/main.py", line 41, in on_message
    voicechannel.play(discord.FFempegPCMAudio(executable='D:/ffmpeg/ffmpeg/bin/ffplay.exe', source='D:/ffmpeg/Horse.mp3'))
AttributeError: module 'discord' has no attribute 'FFempegPCMAudio'
1
Just a note: I would recommend using the discord.ext.commands framework rather than using message.content.startswith(), as it is generally better practice.Jacob Lee
Thanks for the advice :)Alex Møller

1 Answers

1
votes

This issue is just that you are trying to use discord.FFempegPCMAudio when the class is actually discord.FFmpegPCMAudio.

So to correct your code:

if message.content.startswith('$Hest'):
    where = message.content.split(" ")[1]
    channel = get(message.guild.channels, name=where)
    voicechannel = await channel.connect()
    voicechannel.play(
        discord.FFmpegPCMAudio(
            'D:/ffmpeg/Horse.mp3',
            executable='D:/ffmpeg/ffmpeg/bin/ffplay.exe' 
        )
    )

And if you wanted to restructure this to use the discord.ext.commands framework, your code would look something like this:

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix="$")

@bot.command(name="Hest")
async def hest(ctx, where):
    channel = discord.utils.get(ctx.guild.channels, name=where)
    voicechannel = await channel.connect()
    voicechannel.play(
        discord.FFmpegPCMAudio(
            'D:/ffmpeg/Horse.mp3',
            executable='D:/ffmpeg/ffmpeg/bin/ffplay.exe' 
        )
    )

bot.run("<token>")