创建一个删除下载文件的函数

我正在使用此示例代码: https ://github.com/Rapptz/discord.py/blob/master/examples/basic_voice.py

我使用 !yt 命令是因为 !play 命令存在稳定性问题。我需要创建一个消除下载的音乐文件的功能。我曾想过每次播放一首歌曲时都删除整个文件夹,但这个想法对我来说似乎不太好。谁能告诉我该怎么做?


冉冉说
浏览 72回答 1
1回答

慕的地10843

假设你想把它放在命令中,@bot.command(name='del')@commands.is_owner #only bot owner can use thisfor folder in os.listdir('./foldermp3filesarestored'):    if folder.endswith('.mp3'):        os.remove(folder)     else:        print("found file not ending in .mp3")你也可以把它放在 on_ready 的 for 循环中。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python