Discord Bot没有加入语音频道

问题描述:

我正努力使我的机器人进入语音通道,我已经阅读了很多帖子,但没有一个能够解决我的问题,我试图让我的机器人重现yt的声音视频,但它甚至没有加入,我也不知道该怎么做,这是代码:

im struggling to making my bot get into a voice channel, i have already read alot of posts that are here and none of them has been able to solve my problem, im trying to get my bot to reproduce the voice of a yt video but it doesn't even join and i dont know what to do, here is the code:

import os
import discord
import youtube_dl
from random import random, choice, randint
from dotenv import load_dotenv
from discord.ext import commands

load_dotenv()
token = os.getenv("DISCORD_TOKEN")
GUILD = os.getenv("DISCORD_GUILD")
bot = commands.Bot(command_prefix="!")

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

@bot.command(name="join")
async def join(ctx):
    author = ctx.message.author
    channel = author.voice_channel
    await bot.join_voice_channel(channel)

bot.run(token)

bot.join_voice_channel 是discord.py方法,而不是discord.py@rewrite方法.现在,您必须使用 VoiceChannel.connect() .如果您的漫游器已经连接,则可以使用 VoiceClient.move_to (如果您不想要的服务器上只有一个播放器).

bot.join_voice_channel was the discord.py method, not the discord.py@rewrite one. You now have to use VoiceChannel.connect(). If your bot is already connected, then you can use VoiceClient.move_to (If you want only one player on your discord server).

这是您使用这两种方法的方式:

Here's how you use those two methods:

@bot.command(name="join")
async def join(ctx):
    channel = ctx.author.voice.channel
    voice = get(self.bot.voice_clients, guild=ctx.guild)

    if voice and voice.is_connected():
        await voice.move_to(channel)
    else:
        voice = await channel.connect()

参考文献:https://discordpy.readthedocs.io/en/latest/migrating.html?highlight=migrating#voice-changes