【发布时间】:2020-09-17 11:41:04
【问题描述】:
@client.command(description="Pauses the current playing track. Can be resumed with `!resume`.",
brief="Pauses current track.",aliases=['PAUSE'])
async def pause(ctx):
guild_id = ctx.message.guild.id
players[guild_id].pause()
@client.command(description="Resumes the current playing track. Can only be used if current track has
been paused.",
brief="Resumes current track.",
aliases=['RESUME','continue','CONTINUE'])
async def resume(ctx):
guild_id = ctx.message.guild.id
players[guild_id].resume()
@client.command(description="Stops the current playing track.",
brief="Stops current track.",
aliases=['STOP'])
async def stop(ctx):
guild_id = ctx.message.guild.id
players[guild_id].stop()
当我尝试使用暂停、停止和恢复命令时,它给了我 KeyError。触发该错误的整个代码都在那里。错误是这样的:
忽略命令停止中的异常: 回溯(最近一次通话最后): 文件“C:\Users\emirs\PycharmProjects\discordmasterbot\venv\lib\site-packages\discord\ext\commands\core.py”,第 83 行,已包装 ret = 等待 coro(*args, **kwargs) 文件“C:/Users/emirs/PycharmProjects/discordmasterbot/MASTERBOT.py”,第 163 行,停止 玩家[guild_id].stop() 密钥错误:708748879079932016
还有另一种类型的错误:
Traceback(最近一次调用最后一次): 文件“C:\Users\emirs\PycharmProjects\discordmasterbot\venv\lib\site-packages\discord\ext\commands\bot.py”,第 892 行,在调用中 等待 ctx.command.invoke(ctx) 文件“C:\Users\emirs\PycharmProjects\discordmasterbot\venv\lib\site-packages\discord\ext\commands\core.py”,第 797 行,在调用中 等待注入(*ctx.args,**ctx.kwargs) 文件“C:\Users\emirs\PycharmProjects\discordmasterbot\venv\lib\site-packages\discord\ext\commands\core.py”,第 92 行,已包装 从 exc 引发 CommandInvokeError(exc) discord.ext.commands.errors.CommandInvokeError:命令引发异常:KeyError:708748879079932016
【问题讨论】:
-
项目如何插入
players?
标签: python discord.py keyerror