0
votes

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

1 Answers

0
votes

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

References: https://discordpy.readthedocs.io/en/latest/migrating.html?highlight=migrating#voice-changes