首页 文章

我不能使用python discord模块使bot加入不和谐的语音通道

提问于
浏览
0
import discord
from discord.ext import commands
import speech_recognition as sr
description = 'Tutorial Bot'
bot_prefix = '?'
client = commands.Bot(description=description, command_prefix=bot_prefix)
@client.event
async def on_message(message):
    if message.content.startswith("Alice"):
        msg = await client.send_message(message.channel, 'Hello')
@client.event
async def on_voice_state_update():
    with sr.Microphone() as source:
        r = sr.Recognizer()
        audio = r.listen(source)
        command = r.recognize_google(audio)
        msg = await client.send_message(message.channel, comman)
async def joinVoiceChannel():
    channel = client.get_channel("FILL")
    await client.join_voice_channel(channel)
@client.event
async def on_ready():
    print("Logged in")
    print("Name : {}".format(client.user.name))
    print("ID : {}".format(client.user.id))
    print(discord.__version__)
    await joinVoiceChannel()
client.run("FILL")

我正在尝试创建一个可以加入呼叫的机器人,在激活麦克风时听到音频并使用语音识别模块以字符串形式输出消息 . 但是我在机器人加入呼叫时遇到了困难,而且我还没有找到一种方法从discord中获取音频输入 .

登录
名称:BOOS MUSIC
ID:284760930837987338
0.16.8
忽略on_ready Traceback中的异常(最近一次调用最后一次):文件"C:\Users\LMEBA21\AppData\Local\Programs\Python\Python35-32\lib\site-packages\discord\client.py",第307行,在_run_event中从getattr(自身,事件)得到(* args,** kwargs)文件"C:/Users/LMEBA21/AppData/Local/Programs/Python/Python35-32/ALPHA.py",第28行,在on_ready上等待joinVoiceChannel()文件"C:/Users/LMEBA21/AppData/Local/Programs/Python/Python35-32/ALPHA.py" ,第21行,在joinVoiceChannel中等待client.join_voice_channel(通道)文件"C:\Users\LMEBA21\AppData\Local\Programs\Python\Python35-32\lib\site-packages\discord\client.py",第3190行,在join_voice_channel中引发e文件"C:\Users\LMEBA21\AppData\Local\Programs\Python\Python35-32\lib\site-packages\discord\client.py",第3186行,在join_voice_channel中session_id_data =从asyncio.wait_for获取(session_id_future,timeout = 10.0,loop = self.loop )文件"C:\Users\LMEBA21\AppData\Local\Programs\Python\Python35-32\lib\asyncio\tasks.py",第390行,在wait_for引发期货.TimeoutError()concurrent.futures._base.TimeoutError

1 回答

  • 0

    我会评论,但不能因为低代表,你正在犯的两个最大的错误是你应该保存你的Voice对象,例如:

    voice = await client.join_voice_channel(channel)
    

    因为你无疑需要在以后引用它,其次Discord目前不支持从其他用户录制音频,为此你可能需要编写自己的discord包装器并以某种方式集成录音(这有点令人毛骨悚然) .

相关问题