首页 > 解决方案 > 循环命令 (discord.py)

问题描述

@bot.command(pass_context=True)
async def repeat(ctx):

    voice = get(bot.voice_clients, guild=ctx.guild)
    if not voice.is_playing:
            return await ctx.send('Aucune musique joué !')

    await ctx.send("La répétition est activé \n Si vous voulez désactivé : n#stop")

    voice.loop = True
    await ctx.message.add_reaction('✅')

为什么它不会无休止地重复我用我的播放命令播放的音乐?

标签: pythonbotsdiscord

解决方案


嘿,你为什么不试试 itertools。我不是真正的音乐机器人专家,所以暂时不使用 ctx.send()。

from itertools import cycle
import time
import discord
from discord.ext import commands, tasks

client = commands.Bot(command_prefix='.')

@commands.command()
async def repeat():
    music_list = cycle(["song1","song2"])
    while True:
        time.sleep("length of song")
        await ctx.send(next(music_list))

循环是一种非常好的循环方式,您应该真正尝试一下,这是循环如何工作的一个例子,也许这个 tut 可能会有所帮助:

https://www.youtube.com/watch?v=RK8RzuUMYt8


推荐阅读