制作discord.py [VOICE] bot,在pyinstaller之后,声音不起作用

时间:2019-04-23 23:07:11

标签: python pyinstaller discord.py

我正在制作一个discord.py语音机器人,当我第一次使用pyinstaller时,我会遇到一个错误,即如果没有PyNaCl钩子,它将无法播放音频(当我以.py的形式在PyCharm中运行时,它将起作用)要解决我添加的问题:

from PyInstaller.utils.hooks import collect_data_files

datas = collect_data_files('nacl')

这是我能找到的问题的唯一解决方案(我不确定这是否是解决方案,但它不再输出错误了)。现在,当我尝试在pyinstaller之后运行.exe时,控制台将弹出以进行第二次打印,然后退出。

Pyinstaller:

pyinstaller --icon=icon.ico Bot_Spud.py

它是打印出来的:

PyInstaller cannot check for assembly dependencies.
Please install PyWin32 or pywin32-ctypes.

pip install pypiwin32

这是唯一一次出现此问题,我也尝试安装pywin32-ctypes,并且它已经安装

这是我添加到漫游器中以发出声音的代码:

players = {}
queues = {}
@bot.command(pass_context=True, brief="Makes the bot join your channel", aliases=['j', 'jo'])
async def join(ctx):
    channel = ctx.message.author.voice.voice_channel
    await bot.join_voice_channel(channel)
    print("The bot has joined " + str(channel))
    await bot.say("I have joined " + str(channel))


@bot.command(pass_context=True, brief="Makes the bot leave your channel", aliases=['l', 'le', 'lea'])
async def leave(ctx):
    channel = ctx.message.author.voice.voice_channel
    server = ctx.message.server
    voice_client = bot.voice_client_in(server)
    await voice_client.disconnect()
    print("The bot has left " + str(channel))
    await bot.say("I have left " + str(channel))


@bot.command(pass_context=True, brief="This will play a song 'play [url]'", aliases=['pl'])
async def play(ctx, url:str):
    await bot.say("Getting everything ready, playing audio soon")
    print("Someone wants to play music let me get that ready for them...")
    server = ctx.message.server
    print(".")
    voice_client = bot.voice_client_in(server)
    print("..")
    opts = {
        'default_search': 'auto',
        'extractaudio': True,
        'audioformat': "mp3",
        'quiet': True
    }
    print("...")
    player = await voice_client.create_ytdl_player(url, ytdl_options=opts, after=lambda: check_queue(server.id),
                                                   before_options=
                                                   '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5')
    print("....")
    players[server.id] = player
    print(".....")
    player.start()
    print("Playing audio now!")

@bot.command(pass_context=True, brief="Pause the playing music", aliases=['pa', 'p'])
async def pause(ctx):
    id = ctx.message.server.id
    players[id].pause()
    print("Audio PAUSED")
    await bot.say("Audio PAUSED")


@bot.command(pass_context=True, brief="Resume the paused music", aliases=['r', 're'])
async def resume(ctx):
    id = ctx.message.server.id
    players[id].resume()
    print("Audio RESUMED")
    await bot.say("Audio RESUMED")


@bot.command(pass_context=True, brief="Stop the playing music", aliases=['s', 'st'])
async def stop(ctx):
    id = ctx.message.server.id
    players[id].stop()
    print("Audio STOPPED")
    await bot.say("Audio STOPPED")


@bot.command(pass_context=True, brief="Queue music to be played", aliases=['q', 'qu'])
async def queue(ctx, url:str):
    print("Queueing audio now: ")
    server = ctx.message.server
    voice_client = bot.voice_client_in(server)
    player = await voice_client.create_ytdl_player(url)

    if server.id in queues:
        queues[server.id].append(player)
    else:
        queues[server.id] = [player]
    print("Song Queued")
    await bot.say("Song queued")

0 个答案:

没有答案