Python 3.x 音乐机器人的音量只会下降,但不会上升

Python 3.x 音乐机器人的音量只会下降,但不会上升,python-3.x,discord.py,Python 3.x,Discord.py,因此,我有一个名为volume的命令,可以调整音乐机器人的输出音量。我是这样定义函数的: @commands.command(aliases=['sound', 'vol']) async def volume(self, ctx, vol: float): volume = vol / 100 if vol > 100 or vol < 1: embed = discord.Embed(description='Please chose a vo

因此,我有一个名为
volume
的命令,可以调整音乐机器人的输出音量。我是这样定义函数的:

@commands.command(aliases=['sound', 'vol'])
async def volume(self, ctx, vol: float):

    volume = vol / 100

    if vol > 100 or vol < 1:
        embed = discord.Embed(description='Please chose a volume level from 1 to 100', color=discord.Color.red())
        await ctx.send(embed=embed)
        return

    try:
        self.voice.source = discord.PCMVolumeTransformer(self.voice.source, volume=volume)
    except Exception as e:
        error = str(e)
        if "'Music' object has no attribute 'voice'" in error:
            embed = discord.Embed(description='There isn\'t an audio volume to adjust.',
                                  color=discord.Color.red())
            await ctx.send(embed=embed)
            return

    embed = discord.Embed(description=f'Successfully set the volume to **{int(vol)}%**.', color=discord.Color.green())
    await ctx.send(embed=embed)
@commands.command(别名=['sound','vol'])
异步def卷(自身、ctx、卷:浮动):
体积=体积/100
如果体积>100或体积<1:
embed=discord.embed(description='请选择从1到100'的卷级别',color=discord.color.red())
等待ctx.send(嵌入=嵌入)
返回
尝试:
self.voice.source=discord.PCMVolumeTransformer(self.voice.source,volume=volume)
例外情况除外,如e:
错误=str(e)
如果错误的“'Music'对象没有属性'voice'”:
embed=discord.embed(description='没有要调整的音频音量!',
color=discord.color.red())
等待ctx.send(嵌入=嵌入)
返回
embed=discord.embed(description=f'已成功将卷设置为**{int(vol)}%**.',color=discord.color.green()
等待ctx.send(嵌入=嵌入)
当我播放一首歌时,我做
p!第70卷
,该卷的音量确实有所下降。但是当我试图通过做
p来再次提高音量时!第100卷,卷保持不变。基本上,我只能将音量调低,而不能调高

为什么呢?我该如何解决这个问题呢?

找到了解决方案

@client.command(name=“volume”)
异步def卷(ctx,卷:浮点):
voice=get(client.voice\u clients,guild=ctx.guild)

如果为0,则可能需要百分比转换:0.5或50将音量降低50%,1或100保持不变,1.5或150将音量提高50%,因此从技术上讲,我不必执行
vol/100
?我可以只做
vol
?我不知道库,所以我只能推断,但是如果命令期望放大百分比,而你给它一个介于0和100之间的值,它只会变低…哦,我理解。非常感谢。