【问题标题】:discord.py doesn't play sequentially moultiple soundsdiscord.py 不按顺序播放多个声音
【发布时间】:2021-01-07 19:50:19
【问题描述】:

所以我创建了一个“命令”,它在写入时基本上是在播放音频文件。但我的问题是它给了我这样的错误:

raise ClientException('Already connected to a voice channel.')
discord.errors.ClientException: Already connected to a voice channel.

我的代码在这里:

if (".avocado") in content:
        ...
        *bunch of code that doesn't effect the voice*
        ...

        await message.channel.send((f"avocados from mexico: %d" %final))

        channel = message.author.voice.channel
        vc = await channel.connect()
        vc.play(discord.FFmpegPCMAudio(executable="C:\Program Files\Python38\pffmpeg\pffmpeg.exe", source="avocados_from_mexico.mp3"))
        voicest = 1

求任何帮助

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    您可以获取机器人的声音并检查它是否已经连接:

    from discord.utils import get
    
    (...)
    
    if (".avocado") in content:
        (...)
        await message.channel.send((f"avocados from mexico: %d" %final))
    
        channel = message.author.voice.channel
        voice = get(client.voice_clients, guild=message.guild)
    
        if not voice and not voice.is_connected():
            vc = await channel.connect()  
        vc.play(...)
    

    参考资料:

    【讨论】:

    • 是的,但我没有使用 bot.command 我正在使用 client.event 所以它不起作用,更多的问题是如果我使用的是 client.event 我不能使用 bot.command (这对我来说很重要)。
    • 您可以将bot 替换为clientctx.guildmessage.guild ;)
    猜你喜欢
    • 1970-01-01
    • 2017-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-03
    • 2019-07-29
    • 2021-11-07
    • 2013-02-05
    相关资源
    最近更新 更多