【问题标题】:Discord.py bot won't leave a voice chatDiscord.py 机器人不会离开语音聊天
【发布时间】:2022-01-01 06:32:21
【问题描述】:

我目前正在使用这些命令让我的机器人离开/加入 vc。加入工作正常,但离开将不起作用。

import discord
from discord.ext import commands
import youtube_dl

class music(commands.Cog):
  def __init__(self, client):
    self.client = client

  @commands.command()
  async def join(self,ctx):
    if ctx.author.voice is None:
      await ctx.send("You're not in a voice channel!")
    voice_channel = ctx.author.voice.channel
    if ctx.voice_client is None:
      await voice_channel.connect()
    else:
      await ctx.voice_channel.move_to(voice_channel)

  @commands.command()
  async def disconnect(self,ctx):
    await ctx.voice_client.disconnect()

任何帮助理解为什么会非常感激!

【问题讨论】:

标签: python discord bots


【解决方案1】:

尝试:

  @commands.command()
  async def disconnect(self,arg):
    await arg.voice_client.disconnect(force=True)

并将频道名称从 ctx 替换为 arg,因为它将 ctx 作为当前频道(无法输入语音频道 afaik)

【讨论】:

    猜你喜欢
    • 2019-04-08
    • 2018-06-16
    • 2021-05-24
    • 2021-12-02
    • 2020-12-30
    • 2020-10-24
    • 2017-11-20
    • 2021-06-20
    • 1970-01-01
    相关资源
    最近更新 更多