discord.py 音乐曾经有效,但现在出现错误
discord.py music used to work but now im getting an error
我不确定这个错误是什么或如何修复它。有可能修复还是我不应该尝试。
我搜索了这个,因为其他人也有同样的问题,但对我的情况没有任何帮助。
不久前 youtube 删除了不喜欢的计数,最近我尝试 运行 旧的 discord bot 时出现此错误:
Traceback (most recent call last):
File "C:\Users\Judah Kriss\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\Judah Kriss\PycharmProjects\discord\main.py", line 25, in play
await player.queue(url, search=True)
File "C:\Users\Judah Kriss\AppData\Local\Programs\Python\Python310\lib\site-packages\DiscordUtils\Music.py", line 190, in queue
song = await get_video_data(url, search, bettersearch, self.loop)
File "C:\Users\Judah Kriss\AppData\Local\Programs\Python\Python310\lib\site-packages\DiscordUtils\Music.py", line 92, in get_video_data
dislikes = data["dislike_count"]
KeyError: 'dislike_count'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Judah Kriss\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Judah Kriss\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Judah Kriss\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: KeyError: 'dislike_count'
为什么不喜欢计数会影响机器人?
代码:
import discord
from discord.ext import commands
import DiscordUtils
bot = commands.AutoShardedBot(command_prefix=">")
music = DiscordUtils.Music()
@bot.command()
async def join(ctx):
await ctx.author.voice.channel.connect() # Joins author's voice channel
@bot.command()
async def leave(ctx):
await ctx.voice_client.disconnect()
@bot.command()
async def play(ctx, *, url):
player = music.get_player(guild_id=ctx.guild.id)
if not player:
player = music.create_player(ctx, ffmpeg_error_betterfix=True)
if not ctx.voice_client.is_playing():
await player.queue(url, search=True)
song = await player.play()
await ctx.send(f"Playing {song.name}")
else:
song = await player.queue(url, search=True)
await ctx.send(f"Queued {song.name}")
@bot.command()
async def pause(ctx):
player = music.get_player(guild_id=ctx.guild.id)
song = await player.pause()
await ctx.send(f"Paused {song.name}")
@bot.command()
async def resume(ctx):
player = music.get_player(guild_id=ctx.guild.id)
song = await player.resume()
await ctx.send(f"Resumed {song.name}")
@bot.command()
async def stop(ctx):
player = music.get_player(guild_id=ctx.guild.id)
await player.stop()
await ctx.send("Stopped")
@bot.command()
async def loop(ctx):
player = music.get_player(guild_id=ctx.guild.id)
song = await player.toggle_song_loop()
if song.is_looping:
await ctx.send(f"Enabled loop for {song.name}")
else:
await ctx.send(f"Disabled loop for {song.name}")
@bot.command()
async def queue(ctx):
player = music.get_player(guild_id=ctx.guild.id)
await ctx.send(f"{', '.join([song.name for song in player.current_queue()])}")
@bot.command()
async def np(ctx):
player = music.get_player(guild_id=ctx.guild.id)
song = player.now_playing()
await ctx.send(song.name)
@bot.command()
async def skip(ctx):
player = music.get_player(guild_id=ctx.guild.id)
data = await player.skip(force=True)
if len(data) == 2:
await ctx.send(f"Skipped from {data[0].name} to {data[1].name}")
else:
await ctx.send(f"Skipped {data[0].name}")
@bot.command()
async def volume(ctx, vol):
player = music.get_player(guild_id=ctx.guild.id)
song, volume = await player.change_volume(float(vol) / 100) # volume should be a float between 0 to 1
await ctx.send(f"Changed volume for {song.name} to {volume * 100}%")
@bot.command()
async def remove(ctx, index):
player = music.get_player(guild_id=ctx.guild.id)
song = await player.remove_from_queue(int(index))
await ctx.send(f"Removed {song.name} from queue")
bot.run('TOKEN')
提前致谢:)
显示此错误是因为 YouTube API 不再在其 API 中公开不喜欢的次数,因此没有名为 dislikes
的键。这个问题已经提出,但由于业主已经放弃了这个项目,所以不会有任何解决办法。但是,另一个用户已经分叉存储库并继续在该项目上工作,因此您可以执行以下操作:
卸载不受支持的旧版本:
pip uninstall DiscordUtils
安装不再有此错误的新分支版本:
pip install DiscordUtilsMod
现在更改您的代码,而不是
import DiscordUtils
使用
import DiscordUtilsMod
我不确定这个错误是什么或如何修复它。有可能修复还是我不应该尝试。 我搜索了这个,因为其他人也有同样的问题,但对我的情况没有任何帮助。
不久前 youtube 删除了不喜欢的计数,最近我尝试 运行 旧的 discord bot 时出现此错误:
Traceback (most recent call last):
File "C:\Users\Judah Kriss\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\Judah Kriss\PycharmProjects\discord\main.py", line 25, in play
await player.queue(url, search=True)
File "C:\Users\Judah Kriss\AppData\Local\Programs\Python\Python310\lib\site-packages\DiscordUtils\Music.py", line 190, in queue
song = await get_video_data(url, search, bettersearch, self.loop)
File "C:\Users\Judah Kriss\AppData\Local\Programs\Python\Python310\lib\site-packages\DiscordUtils\Music.py", line 92, in get_video_data
dislikes = data["dislike_count"]
KeyError: 'dislike_count'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Judah Kriss\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Judah Kriss\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Judah Kriss\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: KeyError: 'dislike_count'
为什么不喜欢计数会影响机器人?
代码:
import discord
from discord.ext import commands
import DiscordUtils
bot = commands.AutoShardedBot(command_prefix=">")
music = DiscordUtils.Music()
@bot.command()
async def join(ctx):
await ctx.author.voice.channel.connect() # Joins author's voice channel
@bot.command()
async def leave(ctx):
await ctx.voice_client.disconnect()
@bot.command()
async def play(ctx, *, url):
player = music.get_player(guild_id=ctx.guild.id)
if not player:
player = music.create_player(ctx, ffmpeg_error_betterfix=True)
if not ctx.voice_client.is_playing():
await player.queue(url, search=True)
song = await player.play()
await ctx.send(f"Playing {song.name}")
else:
song = await player.queue(url, search=True)
await ctx.send(f"Queued {song.name}")
@bot.command()
async def pause(ctx):
player = music.get_player(guild_id=ctx.guild.id)
song = await player.pause()
await ctx.send(f"Paused {song.name}")
@bot.command()
async def resume(ctx):
player = music.get_player(guild_id=ctx.guild.id)
song = await player.resume()
await ctx.send(f"Resumed {song.name}")
@bot.command()
async def stop(ctx):
player = music.get_player(guild_id=ctx.guild.id)
await player.stop()
await ctx.send("Stopped")
@bot.command()
async def loop(ctx):
player = music.get_player(guild_id=ctx.guild.id)
song = await player.toggle_song_loop()
if song.is_looping:
await ctx.send(f"Enabled loop for {song.name}")
else:
await ctx.send(f"Disabled loop for {song.name}")
@bot.command()
async def queue(ctx):
player = music.get_player(guild_id=ctx.guild.id)
await ctx.send(f"{', '.join([song.name for song in player.current_queue()])}")
@bot.command()
async def np(ctx):
player = music.get_player(guild_id=ctx.guild.id)
song = player.now_playing()
await ctx.send(song.name)
@bot.command()
async def skip(ctx):
player = music.get_player(guild_id=ctx.guild.id)
data = await player.skip(force=True)
if len(data) == 2:
await ctx.send(f"Skipped from {data[0].name} to {data[1].name}")
else:
await ctx.send(f"Skipped {data[0].name}")
@bot.command()
async def volume(ctx, vol):
player = music.get_player(guild_id=ctx.guild.id)
song, volume = await player.change_volume(float(vol) / 100) # volume should be a float between 0 to 1
await ctx.send(f"Changed volume for {song.name} to {volume * 100}%")
@bot.command()
async def remove(ctx, index):
player = music.get_player(guild_id=ctx.guild.id)
song = await player.remove_from_queue(int(index))
await ctx.send(f"Removed {song.name} from queue")
bot.run('TOKEN')
提前致谢:)
显示此错误是因为 YouTube API 不再在其 API 中公开不喜欢的次数,因此没有名为 dislikes
的键。这个问题已经提出,但由于业主已经放弃了这个项目,所以不会有任何解决办法。但是,另一个用户已经分叉存储库并继续在该项目上工作,因此您可以执行以下操作:
卸载不受支持的旧版本:
pip uninstall DiscordUtils
安装不再有此错误的新分支版本:
pip install DiscordUtilsMod
现在更改您的代码,而不是
import DiscordUtils
使用
import DiscordUtilsMod