代码如下:
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.
我该怎么办?
答案 0 :(得分:0)
您可以使用 try-except
语句来捕获错误,或者您可以使用 if 语句来检查机器人是否已经连接到语音通道。
try:
voice = await channel.connect()
except:
print("Bot already connected")