Discord.py:AttributeError:“ NoneType”对象没有属性“ create_ytdl_player”

时间:2018-10-16 18:57:38

标签: python discord discord.py nonetype

我有一个音乐机器人(Discord Server)以下代码: 这是API:https://discordpy.readthedocs.io/en/latest/api.html

@client.event
async def on_message(message):
import os
import random
msgnach = str(message.content)
suche = str(msgnach[6:len(msgnach)])
if(msgnach.startswith("-play")):
    channel = message.author.voice.voice_channel
    server = message
    voice = client.voice_client_in(server)
    if(client.is_voice_connected(server)):
        print("Schon connectet")
        await voice.disconnect()
        sleep(1)
        await client.join_voice_channel(channel)

    else:
        await client.join_voice_channel(channel)
    voice = client.voice_client_in(server)

    if("https" not in suche):
        player = await voice.create_ytdl_player("ytsearch:"+suche)


    else:
        player = await voice.create_ytdl_player(suche, ytdl_options="--skip-download")

    player_dict[server.id] = player

    player.start()

The Bot加入了我的频道,但不播放音乐。 在控制台中,我出现此错误:

Ignoring exception in on_message
Traceback (most recent call last):
 File "D:\Programmieren\Python\PassiBot\venv\lib\site-packages\discord\
     client.py", line 307, in _run_event
 yield from getattr(self, event)(*args, **kwargs)
 File "D:/Programmieren/Python/PassiBot/main.py", line 128, in on_message
player = await voice.create_ytdl_player("ytsearch:"+suche)
AttributeError: 'NoneType' object has no attribute 'create_ytdl_player'

我尝试了很多,但是没有解决。

1 个答案:

答案 0 :(得分:0)

join_voice_channel返回其创建的VoiceClient。您应该可以取消

voice = client.voice_client_in(server) 
通过将上方的代码更改为

if(client.is_voice_connected(server)):
    print("Schon connectet")
    await voice.disconnect()
    await asyncio.sleep(1)
    voice = await client.join_voice_channel(channel)

else:
    voice = await client.join_voice_channel(channel)