【发布时间】:2020-12-11 02:17:38
【问题描述】:
在此处链接的类似帖子中看到了这个问题:Discord.py Bot How to play audio from local files
我对此稍作调整,但我不断收到“未使用的变量‘通道’。 这是我的代码。
async def test(ctx):
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="D:/FFMPEG/ffmpeg.exe", source="<file directory goes here>"))
while vc.is_playing():
time.sleep(.1)
await vc.disconnect()
else:
await ctx.send(str(ctx.author.name) + "is not in a channel.")
【问题讨论】:
-
使用
await asyncio.sleep()而不是time.sleep,它会阻塞你的整个代码,当你播放音乐时你将无法做任何其他事情。
标签: python audio bots discord.py