如果音乐队列清晰,我正试图让我的不和谐机器人(用Python编写)在语音聊天10分钟后断开连接。自从两周前我开始Python以来,我不知道该怎么做,我仍在努力解决问题。
这是机器人结构:
def __init__(self, bot):
self.bot = bot
# All the music related stuff
self.is_playing = False
self.is_paused = False
# Two-dimensional array containing [song, channel]
self.music_queue = []
self.YDL_OPTIONS = {'format': 'bestaudio', 'noplaylist': 'True'}
self.FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
'options': '-vn'}
self.vc = None
这是断开连接部分。现在它只在用户键入命令 /leave后断开连接:
@commands.command(name="leave", aliases=["disconnect", "l", "d"], help="Kick the bot from VC")
async def dc(self, ctx):
self.is_playing = False
self.is_paused = False
await self.vc.disconnect()
我强烈建议您查看discord.py文档,它们有一种称为“任务”的东西,可以让您安排操作
https://discordpy.readthedocs.io/en/stable/ext/tasks/index.html