使用discord.py在vc discord中播放音频-InvalidArgument:传递的通道必须是语音通道

时间:2018-12-25 17:52:56

标签: python django python-3.x bots discord.py

加入语音聊天时,我尝试使用discord.py播放音频,但遇到了问题:

  

InvalidArgument:传递的频道必须是语音频道

我如何使其起作用?

这是我的代码:

import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
import time
import random
from discord import Game

Client = discord.client
client = Bot('.')
Clientdiscord = discord.Client()


@client.command(pass_context=True)
async def yt(ctx):
url = ctx.message.content
url = url.strip('yt')

author = ctx.message.author
voice_channel = author.voice_channel
vc = await client.join_voice_channel(voice_channel)

player = await vc.create_ytdl_player(url)
player.start()

client.run('my Token')

在加入语音频道之后,我厌倦了播放视频:

(.yt https://www.youtube.com/watc........)

错误列表:

忽略命令yt中的异常

Traceback (most recent call last):
File "C:\Users\Hema\AppData\Local\Programs\Python\Python36-32\lib\site- 
packages\discord\ext\commands\core.py", line 50, in wrapped
ret = yield from coro(*args, **kwargs)
File "C:\Users\Hema\Desktop\Music - Copy - Copy.py", line 21, in yt
vc = await client.join_voice_channel(voice_channel)
File "C:\Users\Hema\AppData\Local\Programs\Python\Python36-32\lib\site- 
packages\discord\client.py", line 3172, in join_voice_channel
raise InvalidArgument('Channel passed must be a voice channel')
discord.errors.InvalidArgument: Channel passed must be a voice channel

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\Hema\AppData\Local\Programs\Python\Python36-32\lib\site- 
packages\discord\ext\commands\bot.py", line 846, in process_commands
yield from command.invoke(ctx)
File "C:\Users\Hema\AppData\Local\Programs\Python\Python36-32\lib\site- 
packages\discord\ext\commands\core.py", line 374, in invoke
yield from injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Hema\AppData\Local\Programs\Python\Python36-32\lib\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: InvalidArgument: Channel passed must be a voice channel

0 个答案:

没有答案