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



代码:

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()

当我加入语音通道时,我加入命令,它打印"音乐"。当我再次尝试时,它显示"音乐";discord.errors.ClientException: Already connected to a voice channel.

我该怎么办?

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

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

最新更新