【问题标题】:Discord.py bot leaving voice channelDiscord.py 机器人离开语音频道
【发布时间】:2018-06-16 18:42:58
【问题描述】:

我一直在制作一个不和谐的机器人,它进入一个 vc 播放音频然后离开,但我似乎无法让离开的部分工作。这是我的代码:

# Discord specific import
import discord
from discord.ext import commands
import asyncio

Client = discord.Client()
client = commands.Bot(command_prefix="..")

@client.command(pass_context=True)
async def dan(ctx):
    author = ctx.message.author
    channel = author.voice_channel
    vc = await client.join_voice_channel(channel)
    player = vc.create_ffmpeg_player('dan.mp3', after=lambda: print('done'))
    player.start()
    player.disconnect()

client.run('token')

我没有收到任何错误,但同时机器人没有与 vc 断开连接,我尝试将 'player' 更改为 'client'、'Client' 和 'client.voice'

【问题讨论】:

    标签: python-3.x discord discord.py


    【解决方案1】:

    我的问题是:

    1. 我需要使用:await vc.disconnect()
    2. 我的 websockets 版本太高,需要低于 v4.0.0

    希望这可以帮助人们解决我的问题

    【讨论】:

      【解决方案2】:

      按照here in the docs 的说明尝试vc.disconnect(),因为Client.join_voice_channel(channel) creates a VoiceClient。另外我建议不要有像

      这样的冗余变量

      author = ctx.message.author

      channel = author.voice_channel

      什么时候可以有vc = await client.join_voice_channel(ctx.message.author.voice_channel)

      另外,另一个冗余变量是 Client = discord.Client(),因为您不会在任何地方使用它,而是使用 commands.Bot 实例,因此最好将其删除。

      【讨论】:

      • 这似乎没有用,虽然我没有收到任何错误,但机器人仍然没有断开连接,但是摆脱冗余变量已经奏效。谢谢。
      【解决方案3】:

      player.disconnect() 是一个协程,你应该在它之前使用await 关键字。

      await player.disconnect()
      

      【讨论】:

        猜你喜欢
        • 2019-04-08
        • 2021-04-24
        • 2020-07-17
        • 2020-10-24
        • 1970-01-01
        • 1970-01-01
        • 2020-08-30
        • 2021-11-19
        • 2021-07-06
        相关资源
        最近更新 更多