discord.errors.ClientException:已连接到语音频道音乐机器人

时间:2021-02-15 17:26:07

标签: python discord.py

代码如下:

import discord
from discord.ext import commands
from discord.utils import get


TOKEN = ""
BOT_PREFIX = "!"
bot = commands.Bot(command_prefix=BOT_PREFIX)

@bot.command(pass_context=True, brief="Makes the bot join your channel", aliases=['j', 'jo'])
async def join(ctx):
   channel = ctx.message.author.voice.channel
   print(channel)
   voice = await channel.connect()

当我加入语音频道时,我加入了命令,它打印了“音乐”。当我再次尝试时,它打印出“music”并发送错误:discord.errors.ClientException: Already connected to a voice channel.

我该怎么办?

1 个答案:

答案 0 :(得分:0)

您可以使用 try-except 语句来捕获错误,或者您可以使用 if 语句来检查机器人是否已经连接到语音通道。

try:
    voice = await channel.connect()
except:
    print("Bot already connected")