Discord.py机器人离开语音通道

时间:2018-01-07 16:33:33

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

我一直在做一个不和谐的机器人进入一个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断开连接,我尝试将'播放器'更改为'客户端','客户端'和'client.voice'

3 个答案:

答案 0 :(得分:0)

vc.disconnect(),如Client.join_voice_channel(channel) here in the docs所述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实例,所以最好删除它。

答案 1 :(得分:0)

player.disconnect()是协程,您应该使用之前的await关键字。

await player.disconnect()

答案 2 :(得分:0)

我的问题是:

  1. 我需要使用:await vc.disconnect()
  2. 我的websockets版本太高,需要低于v4.0.0
  3. 希望这有助于解决我的问题的人

相关问题