首页 > 解决方案 > 如何检查所有语音通道以查看是否有人在其中?

问题描述

我正在尝试制作一个机器人,它可以检查所有语音频道,看看是否有人在其中,然后加入人数最多的频道,然后播放声音。我在下面附上了我的代码。

import discord
from discord.ext import commands
from discord.player import FFmpegPCMAudio
from discord.utils import get
import datetime

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

@bot.event
async def on_ready():
    print("Bot is ready")
MINUTE = 0

@bot.command()
async def start(ctx):
    while not bot.is_closed():
        while not "00" in str(MINUTE):
            MINUTE = datetime.datetime.now().minute
            if "00" in str(MINUTE):
                hour = datetime.datetime.now().hour
                number = hour
                while number > 0:
                    # here is where I need the code to check all voice channels and find the one with the most people in
                    voice = await channel.connect()
                    source = FFmpegPCMAudio('audio source')
                    player = voice.play(source)
                    number = number-1



bot.run("my bot token")

标签: pythondiscorddiscord.py

解决方案


您可以遍历所有语音频道成员以找到最多的频道。


推荐阅读