Discord Bot doesn't join voice channel

倾然丶 夕夏残阳落幕 提交于 2021-02-11 16:28:19

问题


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:


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



来源:https://stackoverflow.com/questions/62888711/discord-bot-doesnt-join-voice-channel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!