【发布时间】:2021-03-07 15:55:29
【问题描述】:
我想弄清楚为什么我的机器人会离开语音通道而不是暂停当前播放的音频。这是我的代码以及我尝试过的其他代码:
@commands.command(brief = "Plays a locally hosted song.")
async def play(self, ctx, *, arg):
await ctx.send(f"Joining voice channel: **{ctx.author.voice.channel}**")
destination = ctx.author.voice.channel
await destination.connect()
await ctx.send(f"Joined voice channel: **{ctx.author.voice.channel}**")
voice = discord.utils.get(self.client.voice_clients, guild=ctx.guild)
voice.play(discord.FFmpegPCMAudio(source=f"./audio/{arg}.flac"))
while voice.is_playing():
await asyncio.sleep(.1)
await voice.disconnect()
@commands.command(brief = "Pauses the currently playing song.")
async def pause(self, ctx):
ctx.voice_client.pause()
我也试过了:
@commands.command(brief = "Pauses the currently playing song.")
async def pause(self, ctx):
voice = discord.utils.get(self.client.voice_clients, guild=ctx.guild)
if voice.is_playing():
voice.pause()
else:
await ctx.send("There is currently no audio playing.")
但是,这实现了与以前相同的结果。该机器人在断开呼叫时也不会引发任何错误。任何帮助将不胜感激。
【问题讨论】:
标签: python-3.x discord discord.py