在discord.py中voice.channel.connect()命令不起作用

问题描述 投票:0回答:2

因此,更新我的discord.py 版本后,我的机器人停止工作。似乎在遇到这行代码之后就停止了等待ctx.author.voice.channel.connect()。下面是一段代码

@commands.command()
    async def play(self, ctx, *, song=None):
        playlist = False

        if song is None:
            return await ctx.send('You must include a song to play')

        if ctx.author.voice is None:
            await ctx.send("You are not connected to a voice channel!")
            return

        if ctx.voice_client is None:
            await ctx.author.voice.channel.connect(reconnect=True)
            print(ctx.author.voice.channel.id)

        if song[0:4] != "http" and song[0:3] != "www":
            print("seaking")
            await ctx.send('Searching for a song, it will probably take a few seconds')

            result = await self.search_song(1, song, get_url=True)

            if result is None:
                return await ctx.send("Sorry, I could not find the given song")

            song = result

        url = youtube_dl.YoutubeDL(self.ydl_opts).extract_info(song, download=False)

        """'If' below is for checking whether it`s playlist or not and if it is, it will store this information for later use"""
        if 'entries' in url:
            playlist = True

(我尝试过降级版本,但这没有改变)。我尝试过重新安装软件包并更改意图。但似乎没有任何作用。感谢您提前的帮助

python discord discord.py
2个回答
0
投票

很可能是在更新discord.py时,您忘记包含语音所需的PyNaCl。尝试重新安装带有 [voice] 后缀的discord.py。

pip install -U discord.py[voice]


0
投票

如果我没记错的话,

discord.py
停产,而新维护的替代方案被称为py-cord
。考虑切换到
py-cord
,它可能会解决你的问题。

您也可以尝试:

    检查机器人
  1. 权限
  2. 确保
  3. GUILD_VOICE_STATES
    启用
  4. 连接前确保
  5. ctx.author.voice
     不是 
    None
  6. 安装最新的依赖项:
  7. pip install PyNaCl
© www.soinside.com 2019 - 2024. All rights reserved.