我最近决定创建一个播放MP3音频的Discord bot,但我无法找到解决方案。
最初,错误是这样的:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ClientException: FFmpeg was not found, but we found a fix by writing next to FILE NAME.MP3, executable =
出现上面的错误。你能帮我吗?谢谢。
代码:
import discord
from discord.ext import commands
import random
import json
import math
import os
@client.command()
async def pmartina(ctx):
voicechannel = discord.utils.get(ctx.guild.channels, name='Musica')
vc = await voicechannel.connect()
vc.play(discord.FFmpegPCMAudio(excutable="martina.mp3"), print('done'))
在vc.play(discord.FFmpegPCMAudio...
行中,您使用的是FFmpeg,但是您从未导入过它。
import discord
from discord.ext import commands
import random
import json
import math
import os
import ffmpeg
@client.command()
async def pmartina(ctx):
voicechannel = discord.utils.get(ctx.guild.channels, name='Musica')
vc = await voicechannel.connect()
vc.play(discord.FFmpegPCMAudio(excutable="martina.mp3"), print('done'))
另外,确保下载ffmpeg并正确设置路径。网上有很多视频可以帮助你正确地做到这一点,比如这个是针对Windows的,这个是针对MacOS的。如果你想了解制作音乐机器人的更详细的步骤,请参考这个视频。