如何使用python更改discord bot的音量?
我希望用户能够更改我的discord音乐机器人的音量。我试过这样做,但似乎不起作用。 我已经将vc定义为外部的“东西”,然后用它在try and Exception中播放音乐。我不知道这是否是问题的根源如何使用python更改discord bot的音量?,python,discord,volume,Python,Discord,Volume,我希望用户能够更改我的discord音乐机器人的音量。我试过这样做,但似乎不起作用。 我已经将vc定义为外部的“东西”,然后用它在try and Exception中播放音乐。我不知道这是否是问题的根源 elif contents.startswith("volume"): volume = contents volume = volume.strip("volume ") volume = int(volume)
elif contents.startswith("volume"):
volume = contents
volume = volume.strip("volume ")
volume = int(volume)
if volume <= 100:
volume = volume / 10
vc.source = discord.PCMVolumeTransformer(vc.source)
vc.source.volume = volume
else:
message.channel.send("Please give me a number between 0 and 100!")
elif contents.startswith(“卷”):
体积=内容
卷=卷带(“卷”)
音量=整数(音量)
如果体积预期浮动在0和1.0之间
PCMVolumeTransformer
的初始设置应包括音量,并应放在vc.play()之后。比如vc.source=discord.PCMVolumeTransformer(vc.source,volume=1.0)
然后,在邮件处理中,您可以尝试以下操作:
**通过添加语音连接功能,更新以避免对语音(“vc”)连接使用全局连接。请注意,此功能仅用于卷消息。播放音频的原始连接是单独的,但仍在使用中
if message.content.lower().startswith('volume'):
new_volume=float(message.content.strip('volume'))
voice,voice.source=等待语音连接(消息)
如果0,它仍然会给我UnboundLocalError:分配前引用的局部变量“vc”
,因为我在play命令中设置了vc
,并且音量在我的on消息中处理-我只是在vc设置/连接之前放了一行global vc
。可能应该通过重新设置来更干净地处理它,以避免使用全局设置,但您的全局设置已被外部的“某物”覆盖。要避免使用全局设置,请参阅更新的答案以重新连接vc
-我的代码使用语音
,而不是vc
,因此请进行相应调整。