【问题标题】:Discord.py : AttributeError: 'NoneType' object has no attribute 'create_ytdl_player'Discord.py:AttributeError:“NoneType”对象没有属性“create_ytdl_player”
【发布时间】:2019-03-21 09:19:19
【问题描述】:

我有一个音乐机器人(Discord 服务器)的代码: 这是 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'

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

【问题讨论】:

    标签: python discord discord.py nonetype


    【解决方案1】:

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-11
      • 1970-01-01
      • 1970-01-01
      • 2021-11-02
      • 2014-07-05
      • 2018-05-05
      • 2013-02-11
      • 2018-12-01
      相关资源
      最近更新 更多