首页 > 解决方案 > ctx.send() 不适用于播放音乐

问题描述

我正在使用 Discord.py 制作 Discord Music Bot,但是当我运行 play 命令时,它可以正常播放,但 bot 没有发送它应该发送的消息:

@client.command(description = "Starts playing the specified song.")
async def play(ctx, *, track = 'track'):
    # TURNS SEARCH RESULT INTO URL-------------------
    search = list(track.split(" ")) 
    query = "+".join(str(x) for x in search)
    search_url = "https://www.youtube.com/results?search_query=" + query
    html = urllib.request.urlopen(search_url)
    video_ids = re.findall(r"watch\?v=(\S{11})", html.read().decode())
    url = "https://www.youtube.com/watch?v=" + video_ids[0]
    #------------------------------------------------

    player = music.get_player(guild_id = ctx.guild.id)
    if not player:
        player = music.create_player(ctx, ffmpeg_error_betterfix = True)
    if not ctx.voice_client.is_playing():
        await player.queue(url)
        await player.play()
        video = YouTube()
        await ctx.send("Now playing: " + video.title)
        print("debug")
    else:
        await player.queue(url)
        await ctx.send("The following song has been added to the queue: " + video.title)

谁能告诉我我可能做错了什么?我认为这很明显,但我似乎找不到。要播放音乐,我使用 DiscordUtils。此外,如果您有敏锐的眼光,您可能已经注意到print("debug")代码是否到达那里,如果没有,控制台不会打印。

标签: pythondiscord.py

解决方案


推荐阅读