简体   繁体   English

我无法使用python discord模块使Bot加入Discord语音通道

[英]I cannot make bot join discord voice channels using the python discord module

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")

I'm trying to make a bot that can join the call, hear audio when a microphone is activated and use the speech recognition module to output the message in string form. 我正在尝试制作一个可以加入通话,在激活麦克风时听到声音并使用语音识别模块以字符串形式输出消息的机器人。 However I am having difficulties in the bot joining the call, and I haven't found a way to take an audio input from discord. 但是,我在漫游器加入通话时遇到了困难,并且我还没有找到从不和谐中获取音频输入的方法。

Logged in 登录
Name : BOOS MUSIC 姓名:BOOS MUSIC
ID : 284760930837987338 ID(标识号):284760930837987338
0.16.8 0.16.8
Ignoring exception in on_ready Traceback (most recent call last): File "C:\\Users\\LMEBA21\\AppData\\Local\\Programs\\Python\\Python35-32\\lib\\site-packages\\discord\\client.py", line 307, in _run_event yield from getattr(self, event)(*args, **kwargs) File "C:/Users/LMEBA21/AppData/Local/Programs/Python/Python35-32/ALPHA.py", line 28, in on_ready await joinVoiceChannel() File "C:/Users/LMEBA21/AppData/Local/Programs/Python/Python35-32/ALPHA.py", line 21, in joinVoiceChannel await client.join_voice_channel(channel) File "C:\\Users\\LMEBA21\\AppData\\Local\\Programs\\Python\\Python35-32\\lib\\site-packages\\discord\\client.py", line 3190, in join_voice_channel raise e File "C:\\Users\\LMEBA21\\AppData\\Local\\Programs\\Python\\Python35-32\\lib\\site-packages\\discord\\client.py", line 3186, in join_voice_channel session_id_data = yield from asyncio.wait_for(session_id_future, timeout=10.0, loop=self.loop) File "C:\\Users\\LMEBA21\\AppData\\Local\\Programs\\Python\\Python35-32\\lib\\asyncio\\tasks.py", line 390, in wait_for raise 忽略on_ready追溯中的异常(最近一次调用为最新):文件“ C:\\ Users \\ LMEBA21 \\ AppData \\ Local \\ Programs \\ Python \\ Python35-32 \\ lib \\ site-packages \\ discord \\ client.py”,行307,在来自getattr(_events)的_run_event产量(事件,(args,** kwargs))文件“ C:/Users/LMEBA21/AppData/Local/Programs/Python/Python35-32/ALPHA.py”,第28行,位于on_ready中,等待joinVoiceChannel ()joinVoiceChannel中的第21行的文件“ C:/Users/LMEBA21/AppData/Local/Programs/Python/Python35-32/ALPHA.py”正在等待client.join_voice_channel(channel)文件“ C:\\ Users \\ LMEBA21 \\ AppData \\ join \\ voice_channel中第3190行的\\ Local \\ Programs \\ Python \\ Python35-32 \\ lib \\ site-packages \\ discord \\ client.py“,在e_C:\\ Users \\ LMEBA21 \\ AppData \\ Local \\ Programs \\ Python \\ Python35- join_voice_channel中的32 \\ lib \\ site-packages \\ discord \\ client.py“行3186 session_id_data =从asyncio.wait_for(session_id_future,超时= 10.0,loop = self.loop)产生的文件” C:\\ Users \\ LMEBA21 \\ AppData \\ Local \\ Programs \\ Python \\ Python35-32 \\ lib \\ asyncio \\ tasks.py“,第390行,在wait_for引发 futures.TimeoutError() concurrent.futures._base.TimeoutError futures.TimeoutError()current.futures._base.TimeoutError

I would comment but can't because of low rep, the two biggest mistakes you're making are that you should save your Voice object with something like: 我会发表评论,但由于声望低而不能这样做,您犯的两个最大错误是您应该使用以下方式保存Voice对象:

voice = await client.join_voice_channel(channel)

as you will undoubtedly need to reference it later, and secondly Discord does not currently support recording audio from other users, to do this you would probably need to write your own discord wrapper and somehow integrate recording (Which is a little creepy). 因为您以后肯定会需要引用它,其次,Discord目前不支持录制其他用户的音频,为此,您可能需要编写自己的Discord包装器并以某种方式集成录音(有点令人毛骨悚然)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM