【问题标题】:discord.errors.ClientException: Already connected to a voice channel music botdiscord.errors.ClientException:已经连接到语音频道音乐机器人
【发布时间】:2021-02-16 01:33:48
【问题描述】:

代码如下:

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: 已连接到语音通道。

我该怎么办?

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

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

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

    【讨论】:

    • 什么也没发生。
    • 没关系,它没有连接权限。
    猜你喜欢
    • 2021-02-19
    • 2021-11-21
    • 1970-01-01
    • 2021-05-23
    • 2021-05-27
    • 2018-09-07
    • 2022-01-04
    • 2021-05-27
    • 1970-01-01
    相关资源
    最近更新 更多