基本上就是标题。我已经安装了 ffmpeg 和discord.py[audio]。我只需要了解它是如何工作的。找不到任何本地音频文件的教程。我无法理解文档中的任何内容:/
这是播放本地音频文件的功能。我在使用 FFmpeg 时遇到问题,因此我对 .exe 路径进行了硬编码。另外,我对本地文件的文件路径有疑问,所以我输入了绝对路径。该函数还会在音频播放完毕后删除调用它的命令,以保持整洁。
@bot.command(name="<command_name>")
async def <function_name>(ctx):
# Gets voice channel of message author
voice_channel = ctx.author.channel
channel = None
if voice_channel != None:
channel = voice_channel.name
vc = await voice_channel.connect()
vc.play(discord.FFmpegPCMAudio(executable="C:/ffmpeg/bin/ffmpeg.exe", source="C:<path_to_file>"))
# Sleep while audio is playing.
while vc.is_playing():
sleep(.1)
await vc.disconnect()
else:
await ctx.send(str(ctx.author.name) + "is not in a channel.")
# Delete command after the audio is done playing.
await ctx.message.delete()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)