G
G
Guerro692020-06-22 22:57:17
Python
Guerro69, 2020-06-22 22:57:17

How to play music using discord.py?

How to play music to a bot in a channel?
Here is my code:

import discord, re, asyncio, datetime
from time import *
from function import *
from discord.ext import commands

token, bot, p, tag = session()
bot.remove_command('help')

@bot.command(pass_context=True)
async def play(ctx):
  if ctx.message.author.id == 666249181295542273 or ctx.message.author.id == 383958826245816321:
                await ctx.message.author.voice.channel.connect(reconnect=True)
    ctx.voice_client.play(source='test.mp3', after=None)

The bot connects to the channel, but does not want to play anything and throws two errors:

1. discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: source must an AudioSource not str
2. TypeError: source must an AudioSource not str

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_, 2020-06-23
@Guerro69

The problem is that you are passing the string 'test.mp3' and it expects an object of class discord.AudioSource or its descendants.
You can do this, but here you need ffmpeg installed and added to PATH

ctx.voice_client.play(discord.FFmpegPCMAudio(clip.audiopath), None)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question