因此,我在几个月前用Python编写了一个不和谐机器人,并为其添加了语音支持。我目前在Heroku上托管,当我最初使用Heroku的Opus构建包编写机器人时,事情就正常了。然而,目前在Heroku上运行机器人时,机器人会连接到语音通道,然后机器人会认为它仍然没有连接,即使它在不一致的UI中明显地连接了。
我已经尝试使用不同的Opus构建包,但都无济于事。我目前使用的是这个:https://elements.heroku.com/buildpacks/xrisk/heroku-opus
我还使用了以下库的最新版本
discord.py[voice]
beautifulsoup4
bs4
aiohttp
Pillow
aiofiles
imageio
youtube_dl这是仅用于连接机器人的命令,并且在用于播放音频本身的代码中存在该命令的副本。在两个实例中都观察到了相同的行为。
@commands.command(pass_context=True, aliases=["disconnect"])
async def join(self, ctx):
can_send = await check_can_use(ctx, "join")
if not can_send:
return
global voice
try:
channel = ctx.message.author.voice.channel
voice = get(self.bot.voice_clients, guild=ctx.guild)
# Connect bot to voice channel
if voice and voice.is_connected():
await voice.move_to(channel)
else:
voice = await channel.connect()
print(f"Connected to {channel}\n")
await ctx.send(f"**Connected to {channel}**")
except Exception as e:
print(e)
print("Must be in voice channel")
await ctx.send("**Must be in voice channel**")当在我的电脑上本地运行时,机器人可以正确连接并发送它已连接到服务器的消息。在Heroku上运行时,机器人在连接到语音聊天时会停止。
这行代码:
print(f"Connected to {channel}\n") 就是永远不会跑。机器人在运行后挂起
voice = await channel.connect()我能够打印语音对象,所以我确实知道
voice = get(self.bot.voice_clients, guild=ctx.guild)如预期的那样工作。
在机器人终止之前,异常也不会运行。它的输出可以在这里看到https://pastebin.com/y97Ggvr0。
发布于 2019-10-28 01:29:16
因此,挂起问题似乎是在我上次更新discord.py 1.2.3和1.2.3之间的几个版本中注意到的。Heroku也没有安装1.2.4,而是安装了导致该问题的1.2.3。在我的requirements.txt中强制使用1.2.4已经解决了这个问题。
如果其他人遇到此问题,请确保您使用的是1.2.4版本的discord.pyvoice
https://stackoverflow.com/questions/58576911
复制相似问题