繁体   English   中英

加入语音频道(discord.py)

[英]Join voice channel (discord.py)

当我尝试让我的机器人加入我的语音频道时,出现以下错误:

await client.join_voice_channel(voice_channel) (产生错误的行)

Traceback (most recent call last):
   File "/usr/local/lib/python3.5/site-packages/discord/ext/commands/core.py", line 50, in wrapped
 ret = yield from coro(*args, **kwargs)
 File "bot.py", line 215, in sfx
vc = await client.join_voice_channel(voice_channel)
File "/usr/local/lib/python3.5/site-packages/discord/client.py", line 3176, in join_voice_channel
session_id_future = self.ws.wait_for('VOICE_STATE_UPDATE', session_id_found)
AttributeError: 'NoneType' object has no attribute 'wait_for'

上述异常是以下异常的直接原因:

Traceback (most recent call last):
 File "/usr/local/lib/python3.5/site-packages/discord/ext/commands/bot.py", line 848, in process_commands
yield from command.invoke(ctx)
 File "/usr/local/lib/python3.5/site-packages/discord/ext/commands/core.py", line 369, in invoke
yield from injected(*ctx.args, **ctx.kwargs)
 File "/usr/local/lib/python3.5/site-packages/discord/ext/commands/core.py", line 54, in wrapped
raise CommandInvokeError(e) from e
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'wait_for'

我收到有关频道名称和频道 ID 的错误

功能:

description = "Bot"
bot_prefix = "!"

client = discord.Client()
bot = commands.Bot(description=description, command_prefix=bot_prefix)

@bot.command(pass_context=True)
async def join(ctx):
   author = ctx.message.author
   voice_channel = author.voice_channel
   vc = await client.join_voice_channel(voice_channel)

这是我用来使其工作的代码。

#Bot.py
import discord
from discord.ext import commands
from discord.ext.commands import Bot
from discord.voice_client import VoiceClient
import asyncio

bot = commands.Bot(command_prefix="|")

async def on_ready():
    print ("Ready")

@bot.command(pass_context=True)
async def join(ctx):
    author = ctx.message.author
    channel = author.voice_channel
    await bot.join_voice_channel(channel)

bot.run("token")

摆脱

从discord.voice_client导入VoiceClient行,应该可以。

尝试这个

await bot.join_voice_channel(channel)

暂无
暂无

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

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