Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.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 检查用户是否处于语音频道discord.py中_Python_Ffmpeg_Discord.py - Fatal编程技术网

Python 检查用户是否处于语音频道discord.py中

Python 检查用户是否处于语音频道discord.py中,python,ffmpeg,discord.py,Python,Ffmpeg,Discord.py,我正在制作一个机器人,它将在vc中播放声音。我已编写了加入通话、播放mp3、然后离开通话的代码,但当用户未接听电话时,我会收到以下错误: Ignoring exception in command ring: Traceback (most recent call last): File "C:\Users\max\AppData\Roaming\Python\Python39\site-packages\discord\ext\commands\core.py", li

我正在制作一个机器人,它将在vc中播放声音。我已编写了加入通话、播放mp3、然后离开通话的代码,但当用户未接听电话时,我会收到以下错误:

Ignoring exception in command ring:
Traceback (most recent call last):
  File "C:\Users\max\AppData\Roaming\Python\Python39\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\Users\max\OneDrive\Desktop\Code\DiscordBots\Nokia\Nokia.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:\Users\max\AppData\Roaming\Python\Python39\site-packages\discord\ext\commands\bot.py", line 903, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\max\AppData\Roaming\Python\Python39\site-packages\discord\ext\commands\core.py", line 859, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\max\AppData\Roaming\Python\Python39\site-packages\discord\ext\commands\core.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'
这是我迄今为止的代码:

@client.command()
异步def环(ctx):
频道=ctx.author.voice.channel
vc=等待通道。连接()
播放(discord.ffmpegpcaudio(“Audio/NokiaRingtone.mp3”))
时间。睡眠(5)
等待ctx.voice_client.disconnect()
还有一件事;我想知道为什么当我的机器人与vc断开连接时,我会在聊天中看到这些:

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

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

你只需用If语句检查它是否为非类型

@bot.command()
异步def foo(ctx):
voice\u state=ctx.member.voice
如果语音状态为“无”:
#如果用户不在语音频道中,则退出
return wait ctx.send('您需要在语音频道中才能使用此命令')
#把剩下的代码放在这里