python - 我的代码意外删除了 Discord.py 音乐机器人中的“song.mp3”文件
问题描述
我正在编写我的不和谐机器人,我试图让机器人不尝试连接两次。就像,如果它已经连接任何用户发送另一个“!播放”命令,我不希望它出错。但这不是我的问题。我或我的代码意外删除了我的“song.mp3”文件。我怎么拿回来。我关闭了pycharm,所以我不能做'CRTL + Z'。
@client.command()
async def play(ctx, url: str):
song_there = os.path.isfile("song.mp3")
try:
if song_there:
os.remove("song.mp3")
except PermissionError:
await ctx.send("Şimdi Çalan şarkının bitmesini bekleyin. Yada '!stop' komutunu kullanın.")
return
# connects the voice channel
connected = ctx.author.voice
audio = discord.FFmpegPCMAudio("song.mp3")
voiceChannel = discord.utils.get(ctx.guild.voice_channels, name='music')
if not discord.client.VoiceClient == None: # None being the default value if the bot isnt in a channel (which is why the is_connected() is returning errors)
await voiceChannel.connect()
await ctx.send(f"Joined **{voiceChannel}**")
discord.client.VoiceClient.play()
else:
await ctx.send("I'm already connected!")
audio = discord.FFmpegPCMAudio("song.mp3")
# Dowloads the video from the link given
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
for file in os.listdir("./"):
if file.endswith(".mp3"):
os.rename(file, "song.mp3")
解决方案
尝试在回收站中搜索它...
推荐阅读
- ssh - 如何在 Github Actions 中使用 ssh 身份文件
- javascript - 未选中的 Vuetify v-checkbox 图标没有为 Font Awesome 4 应用正确的类
- dictionary - 是否可以创建一个可以验证哈希图/字典而不是对象的 JSON 模式?
- c++ - 我的叉子输出不正确
- c++ - 使用单个 makefile 编译 C 和 C++
- python - Geopandas 中的自定义 Choropleth 标签
- javascript - 如何过滤表示对象的字符串
- python - 如何使用虚拟环境调试 python 函数应用程序
- javascript - 我如何编辑这个以展开 onmouseenter 和折叠 onmouseleave
- c++ - 使用 Caffe 和 CUDA 的 C++ 程序