Python 检查该人是否处于语音通道混乱状态

Python 检查该人是否处于语音通道混乱状态,python,discord,discord.py,Python,Discord,Discord.py,我在我的discord机器人中做了一个命令,当命令G!tutturu已发送。当您处于语音频道时,它可以正常工作,但当您不在而不是发送用户不在频道时,我会收到一个错误。我知道这个错误意味着什么,但我不知道如何避免它 import discord import os from discord.ext.commands import Bot import datetime from discord.ext import commands import asyncio import praw impor

我在我的discord机器人中做了一个命令,当命令
G!tutturu
已发送。当您处于语音频道时,它可以正常工作,但当您不在而不是发送用户不在频道时,我会收到一个错误。我知道这个错误意味着什么,但我不知道如何避免它

import discord
import os
from discord.ext.commands import Bot
import datetime
from discord.ext import commands
import asyncio
import praw
import audioread
import time

TOKEN = "____"
bot = commands.Bot(command_prefix="G!")
client = discord.Client()
split_1 = "I'm"
split_2 = "i'm"
split_3 = "Im"
split_4 = "im"
rest = None
reddit = praw.Reddit(client_id='', client_secret='',
                     username='', password='', user_agent='test')

subreddit = reddit.subreddit('GameDeals')
new_GameDeals = subreddit.new(limit=50)


@bot.command(name='tutturu')
async def tutturu(ctx):
    path_mp3 = "Tutturuu.mp3"
    path_ffmpeg = r"C:\ffmpeg\bin\ffmpeg.exe"
    voice_channel = ctx.author.voice.channel
    if voice_channel is not None:
        vc = await voice_channel.connect()
        vc.play(discord.FFmpegPCMAudio(executable=path_ffmpeg, source=path_mp3))
        with audioread.audio_open(path_mp3) as f:
            await asyncio.sleep(f.duration)
        await vc.disconnect()
    else:
        await ctx.channel.send(str(ctx.author.name) + "is not in a channel.")
    await ctx.message.delete()


@bot.command(name='GameDeals')
async def GameDeals(ctx):
    for post in new_GameDeals:
        if '[STEAM]' in post.title and ('free' in post.title or 'Free' in post.title or '100%' in post.title):
            await ctx.message.channel.send(post.title)
        elif '[Steam]' in post.title and ('free' in post.title or 'Free' in post.title or '100%' in post.title):
            await ctx.message.channel.send(post.title)
        elif '[Epic Games]' in post.title and ('free' in post.title or 'Free' in post.title or '100%' in post.title):
            await ctx.message.channel.send(post.title)
        elif '[Uplay]' in post.title and ('free' in post.title or 'Free' in post.title or '100%' in post.title):
            await ctx.message.channel.send(post.title)
        elif '[Humble Bundle]' in post.title and ('free' in post.title or 'Free' in post.title or '100%' in post.title):
            await ctx.message.channel.send(post.title)
        elif '[Epic]' in post.title and ('free' in post.title or 'Free' in post.title or '100%' in post.title):
            await ctx.message.channel.send(post.title)
        elif '[UPLAY]' in post.title and ('free' in post.title or 'Free' in post.title or '100%' in post.title):
            await ctx.message.channel.send(post.title)


@bot.command(name='Help')
async def Help(ctx):
    await ctx.message.channel.send('1) G!tutturu speelt tutturu af')
    await ctx.message.channel.send('2) G!GameDeals toont je de gratis game deals van het moment')


@bot.event
async def on_message(message):
    if 'Creeper' in message.content or 'creeper' in message.content and not message.author.bot:
        await message.channel.send('OW MAN')
    if 'ah fuck' in message.content or 'Ah fuck' in message.content and not message.author.bot:
        await message.channel.send("I can't believe you've done this")
    if "Who didn't flush the toilet when they took a shat" in message.content and not message.author.bot:
        await message.channel.send('DISGUUUSTAAAN!!!!!')
        await message.channel.send(file=discord.File('disgustang.png'))
    if '❤' in message.content and not message.author.bot:
        await message.channel.send('❤')
    if message.content == 'koekoek' or message.content == 'Koekoek' and not message.author.bot:
        await message.channel.send(datetime.datetime.now())
    if "I'm" in message.content and not message.author.bot:
        rest = message.content.partition(split_1)[2]
        await message.channel.send('Hello' + rest + ", I'm dad")
    if "i'm" in message.content and not message.author.bot:
        rest = message.content.partition(split_2)[2]
        await message.channel.send('Hello' + rest + ", I'm dad")
    if "Im" in message.content and not message.author.bot:
        rest = message.content.partition(split_3)[2]
        await message.channel.send('Hello' + rest + ", I'm dad")
    if "im" in message.content and not message.author.bot:
        rest = message.content.partition(split_4)[2]
        await message.channel.send('Hello' + rest + ", I'm dad")
    if 'fire' in message.content or 'Fire' in message.content or 'lit' in message.content or 'Lit' in message.content and not message.author.bot:
        await message.channel.send('The issue is here:

voice_channel = ctx.author.voice.channel
    if voice_channel is not None:
导入不一致
导入操作系统
从discord.ext.commands导入Bot
导入日期时间
从discord.ext导入命令
导入异步
进口婴儿车
导入音频读取
导入时间
令牌=“\uuuuuuuuuuu”
bot=commands.bot(command_prefix=“G!”)
client=discord.client()
split_1=“我是”
split_2=“我是”
split_3=“Im”
split_4=“im”
剩余=无
reddit=praw.reddit(客户端id='',客户端机密='',
用户名=“”,密码=“”,用户\u agent='test')
subreddit=reddit.subreddit(‘游戏交易’)
new_GameDeals=subreddit.new(限制=50)
@bot.command(name='tutturu')
异步def tutturu(ctx):
path_mp3=“Tutturuu.mp3”
路径\u ffmpeg=r“C:\ffmpeg\bin\ffmpeg.exe”
语音频道=ctx.author.voice.channel
如果语音信道不是无:
vc=等待语音信道。连接()
play(discord.ffmpegpcaudio(可执行文件=path\u ffmpeg,source=path\u mp3))
将audioread.audio_打开(路径为mp3)作为f:
等待异步睡眠(f.持续时间)
等待vc.disconnect()
其他:
等待ctx.channel.send(str(ctx.author.name)+“不在频道中”)
等待ctx.message.delete()
@bot.command(name='GameDeals')
异步def GameDeals(ctx):
有关在新游戏交易中发布的信息:
如果post.title中的“[STEAM]”和post.title中的“free”或post.title中的“free”或post.title中的“100%”,则:
等待ctx.message.channel.send(post.title)
如果post.title中的“[Steam]”和post.title中的(“free”或post.title中的“free”或post.title中的“100%”,则省略):
等待ctx.message.channel.send(post.title)
elif“[Epic Games]”在post.title和(“免费”在post.title或“免费”在post.title或“100%”在post.title中):
等待ctx.message.channel.send(post.title)
如果post.title中的“[Uplay]”和post.title中的('free'或post.title中的'free'或post.title中的'100%”),则:
等待ctx.message.channel.send(post.title)
如果post.title中的“[Humble Bundle]”和post.title中的“'free”或post.title中的“free”或post.title中的“100%”,则:
等待ctx.message.channel.send(post.title)
如果post.title中的“[Epic]”和post.title中的“'free'”或post.title中的“free”或post.title中的“100%”,则:
等待ctx.message.channel.send(post.title)
如果post.title中的“[UPLAY]”和post.title中的('free'或post.title中的'free'或post.title中的'100%”),则:
等待ctx.message.channel.send(post.title)
@命令(name='Help')
异步def帮助(ctx):
等待ctx.message.channel.send('1)G!图图鲁语(图图图鲁语)
等待ctx.message.channel.send('2)G!游戏交易toont je de gratis游戏交易van het瞬间)
@机器人事件
异步def on_消息(消息):
如果message.content中的“爬行器”或message.content中的“爬行器”而不是message.author.bot:
等待消息。频道。发送('OW MAN')
如果message.content中的'ah fuck'或message.content中的'ah fuck'而不是message.author.bot:
等待message.channel.send(“我不敢相信你这么做了”)
如果message.content而不是message.author.bot中的“谁在洗澡时没有冲马桶”:
等待消息。频道。发送('DISGUUUSTAAAN!!!!!)
等待message.channel.send(file=discord.file('ostang.png'))
如果❤' 在message.content而不是message.author.bot中:
等待消息。频道。发送('❤')
如果message.content=='koekoek'或message.content=='koekoek'而不是message.author.bot:
等待message.channel.send(datetime.datetime.now())
如果message.content中的“我在”,而不是message.author.bot中的“我在”:
rest=message.content.partition(split_1)[2]
等待消息。频道。发送('Hello'+rest+“,我是爸爸”)
如果message.content中的“我在”,而不是message.author.bot中的“我在”:
rest=message.content.partition(split_2)[2]
等待消息。频道。发送('Hello'+rest+“,我是爸爸”)
如果message.content中的“Im”而不是message.author.bot中的“Im”:
rest=message.content.partition(split_3)[2]
等待消息。频道。发送('Hello'+rest+“,我是爸爸”)
如果message.content中的“im”而不是message.author.bot中的“im”:
rest=message.content.partition(split_4)[2]
等待消息。频道。发送('Hello'+rest+“,我是爸爸”)
如果message.content中的“fire”或message.content中的“fire”或message.content中的“lit”或message.content中的“lit”,而不是message.author.bot:
等待消息.channel.send(“问题在这里:

voice_state = ctx.author.voice
if voice is not None:
    ....
Member.voice
在成员不在语音频道时返回
None
,因此您应该首先检查该选项