【问题标题】:Discord Bot doesn't join voice channelDiscord Bot 不加入语音频道
【发布时间】:2020-11-03 09:47:14
【问题描述】:

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

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)

【问题讨论】:

    标签: python python-3.x discord discord.py


    【解决方案1】:

    bot.join_voice_channel 是 discord.py 方法,而不是 discord.py@rewrite 方法。您现在必须使用VoiceChannel.connect()。如果您的机器人已经连接,那么您可以使用VoiceClient.move_to(如果您希望您的 discord 服务器上只有一个播放器)。

    这两种方法的使用方法如下:

    @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

    【讨论】:

    • 非常感谢!这工作得很好,我真的很感激。
    猜你喜欢
    • 2020-11-04
    • 2020-06-26
    • 1970-01-01
    • 2022-01-23
    • 2021-01-05
    • 2017-06-22
    • 2020-12-21
    • 1970-01-01
    • 2020-10-07
    相关资源
    最近更新 更多