Discord.py: AttributeError: объект 'NoneType' не имеет атрибута 'create_ytdl_player' - PullRequest
0 голосов
/ 16 октября 2018

У меня есть этот код для музыкального бота (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()

Бот присоединился к моему каналу, но не воспроизводит музыку.В консоли у меня есть эта ошибка:

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 голосов
/ 16 октября 2018

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