def play_file(self, ctx, sound, volume=1):
"""Plays a file from the local filesystem"""
if ctx.voice_client is None:
if ctx.author.voice.channel:
await ctx.author.voice.channel.connect()
else:
return await ctx.send("Not connected to a voice channel.")
if ctx.voice_client.is_playing():
ctx.voice_client.stop()
def done(e):
if e:
print("Player error: %s" % e)
if not ctx.voice_client.is_playing():
ctx.bot.loop.create_task(ctx.voice_client.disconnect())
source = discord.PCMVolumeTransformer(
discord.FFmpegPCMAudio(join(folder, sound)))
source.volume = volume
ctx.voice_client.play(source, after=done)
# await ctx.send('Now playing: {}'.format(query))
评论列表
文章目录