gpt4 book ai didi

python - 如何使用 python 更改我的不和谐机器人的音量?

转载 作者:行者123 更新时间:2023-12-04 10:00:46 25 4
gpt4 key购买 nike

我希望用户能够更改我的不和谐音乐机器人的音量。我试过这样做,但它似乎不起作用。
我已经将 vc 定义为外部的“某物”,然后在 try 和 except 中使用它来播放音乐。我想知道这是否是导致问题的原因。

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!")

最佳答案

PCMVolumeTransformer期望在 0 和 1.0 之间 float 。
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 = await voice_connect(message)
if 0 <= new_volume <= 100:
new_volume = new_volume / 100
voice.source.volume = new_volume
else:
await message.channel.send('Please enter a volume between 0 and 100')

@bot.command()
async def voice_connect(message):
if message.author == bot.user:
return

channel = message.author.voice.channel
voice = get(bot.voice_clients, guild=message.guild)

if voice and voice.is_connected():
return voice, voice.source
else:
voice = await channel.connect()
voice.source = discord.PCMVolumeTransformer(voice.source, volume=1.0)
print(f"The bot has connected to {channel}\n")

return voice, voice.source

关于python - 如何使用 python 更改我的不和谐机器人的音量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61832617/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com