Python Discord.py';通道对象没有属性create\u ytdl\u player

Python Discord.py';通道对象没有属性create\u ytdl\u player,python,discord,Python,Discord,各位晚上好。我目前正在为我和我的朋友编写一个Discord机器人,以便在我们的语音频道播放YouTube URL上的音乐。我一直在使用discord.py的API引用来创建它,但我面临一个恼人的错误。在运行时,我看到: AttributeError: 'Channel' object has no attribute 'create_ytdl_player' 我还安装了youtube dl模块。下面是我的完整代码。谢谢你的评论 import discord from discord.ext i

各位晚上好。我目前正在为我和我的朋友编写一个Discord机器人,以便在我们的语音频道播放YouTube URL上的音乐。我一直在使用discord.py的API引用来创建它,但我面临一个恼人的错误。在运行时,我看到:

AttributeError: 'Channel' object has no attribute 'create_ytdl_player'
我还安装了youtube dl模块。下面是我的完整代码。谢谢你的评论

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

bot = commands.Bot(command_prefix='!')

@bot.command(pass_context=True)
async def play(ctx):

voice = ctx.message.author.voice.voice_channel
await bot.join_voice_channel(voice)

url = 'some_url'
player = await voice.create_ytdl_player(url)

bot.run(NO TOKEN 4 U)

我认为您在错误的对象上调用了
create\u ytdl\u player
方法。您不希望在
语音
上调用它,而是希望在对
bot.join\u voice\u channel
进行的异步调用的返回值上调用它

它是这样显示的:

voice = await client.join_voice_channel(channel)
player = await voice.create_ytdl_player('https://www.youtube.com/watch?v=d62TYemN6MQ')
player.start()
但是示例中的
voice
变量的含义与代码中的不同。您的
语音
相当于示例代码的
频道

尝试以下方法,使用一些新的变量名:

voice_channel = ctx.message.author.voice.voice_channel
voice_client = await bot.join_voice_channel(voice_channel)

url = 'some_url'
player = await voice_client.create_ytdl_player(url)
您可能还需要在播放器上调用
start