• <i id='bvi3V'><tr id='bvi3V'><dt id='bvi3V'><q id='bvi3V'><span id='bvi3V'><b id='bvi3V'><form id='bvi3V'><ins id='bvi3V'></ins><ul id='bvi3V'></ul><sub id='bvi3V'></sub></form><legend id='bvi3V'></legend><bdo id='bvi3V'><pre id='bvi3V'><center id='bvi3V'></center></pre></bdo></b><th id='bvi3V'></th></span></q></dt></tr></i><div id='bvi3V'><tfoot id='bvi3V'></tfoot><dl id='bvi3V'><fieldset id='bvi3V'></fieldset></dl></div>
    <tfoot id='bvi3V'></tfoot>
    <legend id='bvi3V'><style id='bvi3V'><dir id='bvi3V'><q id='bvi3V'></q></dir></style></legend>

      <small id='bvi3V'></small><noframes id='bvi3V'>

          <bdo id='bvi3V'></bdo><ul id='bvi3V'></ul>
      1. 检查用户是否在语音频道 discord.py

        时间:2023-10-10
      2. <tfoot id='DU2ag'></tfoot>

          <bdo id='DU2ag'></bdo><ul id='DU2ag'></ul>
              <tbody id='DU2ag'></tbody>
              <i id='DU2ag'><tr id='DU2ag'><dt id='DU2ag'><q id='DU2ag'><span id='DU2ag'><b id='DU2ag'><form id='DU2ag'><ins id='DU2ag'></ins><ul id='DU2ag'></ul><sub id='DU2ag'></sub></form><legend id='DU2ag'></legend><bdo id='DU2ag'><pre id='DU2ag'><center id='DU2ag'></center></pre></bdo></b><th id='DU2ag'></th></span></q></dt></tr></i><div id='DU2ag'><tfoot id='DU2ag'></tfoot><dl id='DU2ag'><fieldset id='DU2ag'></fieldset></dl></div>

              <small id='DU2ag'></small><noframes id='DU2ag'>

                <legend id='DU2ag'><style id='DU2ag'><dir id='DU2ag'><q id='DU2ag'></q></dir></style></legend>
                1. 本文介绍了检查用户是否在语音频道 discord.py的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在制作一个可以在 vc 中播放声音的机器人.我已经编写了加入通话的代码,播放 mp3,然后离开通话,但是当用户不在通话中时,我收到此错误:

                  I am making a bot that will play sounds in a vc. I have made the code to join the call, play the mp3, then leave the call but when the user is not in a call I get this error:

                  Ignoring exception in command ring:
                  Traceback (most recent call last):
                    File "C:UsersmaxAppDataRoamingPythonPython39site-packagesdiscordextcommandscore.py", line 85, in wrapped
                      ret = await coro(*args, **kwargs)
                    File "C:UsersmaxOneDriveDesktopCodeDiscordBotsNokiaNokia.py", line 91, in ring
                      channel = ctx.author.voice.channel
                  AttributeError: 'NoneType' object has no attribute 'channel'
                  
                  The above exception was the direct cause of the following exception:
                  
                  Traceback (most recent call last):
                    File "C:UsersmaxAppDataRoamingPythonPython39site-packagesdiscordextcommandsot.py", line 903, in invoke
                      await ctx.command.invoke(ctx)
                    File "C:UsersmaxAppDataRoamingPythonPython39site-packagesdiscordextcommandscore.py", line 859, in invoke
                      await injected(*ctx.args, **ctx.kwargs)
                    File "C:UsersmaxAppDataRoamingPythonPython39site-packagesdiscordextcommandscore.py", line 94, in wrapped
                      raise CommandInvokeError(exc) from exc
                  discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'channel'
                  

                  这是我目前拥有的代码:

                  This is my code that I have so far:

                  @client.command()
                  async def ring(ctx):
                      channel = ctx.author.voice.channel
                      vc = await channel.connect()
                      vc.play(discord.FFmpegPCMAudio("Audio/NokiaRingtone.mp3"))
                      time.sleep(5)
                      await ctx.voice_client.disconnect()
                  

                  还有一件事;我想知道为什么当我的机器人与 vc 断开连接时,我会在聊天中得到这些:

                  One more thing; I was wondering why I get these in the chat when my bot disconnects from the vc:

                  websocket connection is closing.
                  websocket connection is closing.
                  websocket connection is closing.
                  

                  如果有人可以帮我检查用户是否在语音频道中,并告诉我为什么我的控制台中有这三行,那就太好了.

                  If anyone could help me check if the user is in a voice channel and tell me why I get those three lines in my console that would be great.

                  推荐答案

                  你可以简单地用 if 语句检查它是否不是非类型

                  You can simply check if it's not a nonetype with an if statement

                  @bot.command()
                  async def foo(ctx):
                      voice_state = ctx.member.voice
                  
                      if voice_state is None:
                          # Exiting if the user is not in a voice channel
                          return await ctx.send('You need to be in a voice channel to use this command')
                  
                      # Put the rest of the code here
                  

                  这篇关于检查用户是否在语音频道 discord.py的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:discord.py 试图删除用户的所有角色 下一篇:如何使用 discord.py 获取不和谐服务器中所有成员

                  相关文章

                  最新文章

                  <tfoot id='zNBvM'></tfoot>

                    <bdo id='zNBvM'></bdo><ul id='zNBvM'></ul>
                2. <legend id='zNBvM'><style id='zNBvM'><dir id='zNBvM'><q id='zNBvM'></q></dir></style></legend>

                    <i id='zNBvM'><tr id='zNBvM'><dt id='zNBvM'><q id='zNBvM'><span id='zNBvM'><b id='zNBvM'><form id='zNBvM'><ins id='zNBvM'></ins><ul id='zNBvM'></ul><sub id='zNBvM'></sub></form><legend id='zNBvM'></legend><bdo id='zNBvM'><pre id='zNBvM'><center id='zNBvM'></center></pre></bdo></b><th id='zNBvM'></th></span></q></dt></tr></i><div id='zNBvM'><tfoot id='zNBvM'></tfoot><dl id='zNBvM'><fieldset id='zNBvM'></fieldset></dl></div>
                  1. <small id='zNBvM'></small><noframes id='zNBvM'>