Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 带有discord.py语句_Python 3.x_Discord.py - Fatal编程技术网

Python 3.x 带有discord.py语句

Python 3.x 带有discord.py语句,python-3.x,discord.py,Python 3.x,Discord.py,给出此错误: with ctx.message.author.voice.channel.members as users: for user in users: await user.edit(voice_channel=None) 我在以下情况下得到了相同的错误:使用ctx.author.voice.channel作为频道: 我查看了discord.py文档,但没有发现任何有用的内容 另外,这段代码在一两个月前就开始工

给出此错误:

with ctx.message.author.voice.channel.members as users:
                for user in users:
                    await user.edit(voice_channel=None)
我在以下情况下得到了相同的错误:
使用ctx.author.voice.channel作为频道:

我查看了discord.py文档,但没有发现任何有用的内容


另外,这段代码在一两个月前就开始工作了,当我试图重新启动bot时,“随机”停止了工作

我想你只是想定义一个变量:

users=ctx.message.author.voice.channel.members
对于用户中的用户:
等待用户编辑(语音频道=无)
如果要使用上下文管理器,请使用
contextlib.nullcontext

从contextlib导入nullcontext
使用nullcontext(ctx.message.author.voice.channel.members)作为用户:
对于用户中的用户:
等待用户编辑(语音频道=无)
另外,要断开用户与语音频道的连接,请使用
成员。将
None
作为参数,而不是
Member.edit(语音频道=None)

等待用户。移动到(无)
参考资料:

    • 我想您只需要定义一个变量:

      users=ctx.message.author.voice.channel.members
      对于用户中的用户:
      等待用户编辑(语音频道=无)
      
      如果要使用上下文管理器,请使用
      contextlib.nullcontext

      从contextlib导入nullcontext
      使用nullcontext(ctx.message.author.voice.channel.members)作为用户:
      对于用户中的用户:
      等待用户编辑(语音频道=无)
      
      另外,要断开用户与语音频道的连接,请使用
      成员。将
      None
      作为参数,而不是
      Member.edit(语音频道=None)

      等待用户。移动到(无)
      
      参考资料:

      上下文管理器的用途是什么?你想达到什么目标?不,它没有“随机”停止,因为它本来就不应该工作。我根本不知道discord API,但是
      频道。成员对我来说并不支持上下文。也许这会帮助您解除阻塞:@ukaszKwieciński我只是想清理代码,让它更清晰。我肯定这是可行的,但也肯定这并没有停止随机工作。你是想定义一个变量吗
      users=ctx.message.author.voice.channel.members
      ?@ukaszKwieciński也许这是最好的方法,是的,但我只是好奇它是否有效。不管怎样,谢谢你上下文管理器的目的是什么?你想达到什么目标?不,它没有“随机”停止,因为它本来就不应该工作。我根本不知道discord API,但是
      频道。成员对我来说并不支持上下文。也许这会帮助您解除阻塞:@ukaszKwieciński我只是想清理代码,让它更清晰。我肯定这是可行的,但也肯定这并没有停止随机工作。你是想定义一个变量吗
      users=ctx.message.author.voice.channel.members
      ?@ukaszKwieciński也许这是最好的方法,是的,但我只是好奇它是否有效。无论如何谢谢你
      with ctx.message.author.voice.channel.members as users:
      AttributeError: __enter__
      
      The above exception was the direct cause of the following exception:
      discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: __enter__