python - 循环命令 (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('✅')
为什么它不会无休止地重复我用我的播放命令播放的音乐?
解决方案
嘿,你为什么不试试 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 可能会有所帮助:
推荐阅读
- ionic-framework - 离子如何改变离子含量>主要风格?
- google-cloud-platform - 无法在 Datafusion 中上传 CDAP 自定义插件
- python - python 程序可以在 Thonny Python IDE 上的打印机上打印整个窗口,但不能在 LXTerminal 上
- node.js - 通过 path.resolve.apply(this, ...) 调用 path.resolve() 的效果是什么?
- sqlalchemy - Sqlalchemy + Firebird:如何删除引号
- python - 如何使用python提取网站的全部数据?
- pandas - python pandas + named_bitfield => 嵌入式系统的内存映射
- javafx - JavaFX 将 Wingdings 字符设置为标签
- php - PHP计算真正的大/大数字显示错误的结果
- javascript - 在新窗口中加载新的 A-Frame 场景