@Guerro69

Как проигрывать музыку с помощью discord.py?

Как проиграть музыку боту в канале?
Вот мой код:
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)

Бот подключается к каналу, но проигрывать ничего не хочет и выдаёт две ошибки:

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
  • Вопрос задан
  • 4779 просмотров
Решения вопроса 1
@mrxor
Simple is better than complex
Проблема в том, что вы передаете строку 'test.mp3', а там ожидается объект класса discord.AudioSource или его наследников.
Можно сделать так, но тут нужен установленный и добавленный в PATH ffmpeg
ctx.voice_client.play(discord.FFmpegPCMAudio(clip.audiopath), None)
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы