python - Bot 无法连接到语音通道 - discord.py 重写
问题描述
我正在使用 discord.py 重写制作一个不和谐的机器人,但我最近遇到了一个问题。
我已发出加入用户语音频道的命令。问题是,当我在本地 PC 上运行它时,我的命令运行良好,但现在我试图在树莓派上运行它,它在连接到语音通道时失败。
我已经尝试安装所有依赖项,但我无法让它工作。命令代码:
@bot.command()
async def join(ctx):
channel = ctx.message.author.voice.channel
voice = get(bot.voice_clients, guild=ctx.guild)
if voice and voice.is_connected():
await voice.move_to(channel)
else:
voice = await channel.connect()
await ctx.send("I joined the channel!")
没有提出任何例外。
解决方案
您正在使用错误的方式连接到语音通道。尝试使用此代码。
它识别用户的位置并在该语音通道中连接。
@bot.command(name='join', invoke_without_subcommand=True)
async def join(ctx):
destination = ctx.author.voice.channel
if ctx.voice_state.voice:
await ctx.voice_state.voice.move_to(destination)
return
ctx.voice_state.voice = await destination.connect()
await ctx.send(f"Joined {ctx.author.voice.channel} Voice Channel")
推荐阅读
- css - 即使安装了所有东西,如何解决引导程序不起作用的问题?
- python-3.x - 词形还原嵌套列表中的单词
- android - 伙计们,我正在用颤振编码一些东西,我从变量中取 null 你能帮我吗
- javascript - 车道分配算法
- html - 正确的结构未在 Html Display Flex 上显示
- javascript - 基于技能指数从 10 人列表中组成两个团队的算法
- bash - 将 xargs 与 cat 和 grep 结合使用
- node.js - 如何将 API 调用响应存储为对象或将数组解析为 JSON?
- docker - 具有自动缩放功能的 ECS 集群中的 RabbitMQ
- graphql - 深度合并片段