python - 无法在 Discord 中编辑机器人自己的消息
问题描述
@client.command()
async def inspire(context):
wait_msg = await context.send("Finding a quote for ya...")
await wait_msg.edit(content=inspire())
Error : RuntimeWarning: coroutine 'Command.__call__' was never awaited
await wait_msg.edit(content=inspire())
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
此方法适用于 @client.event ,但我在 @client.command 上遇到运行时错误,我是机器人开发的新手,所以谁能告诉我如何解决这个问题。
解决方案
@client.command()
async def inspire(context):
wait_msg = await context.send("Finding a quote for ya...")
await wait_msg.edit(content="this is the edit")
当您要求进行编辑时,您必须更改消息的实际属性,这意味着如果您想更改内容,您需要给他一个新的内容来更改。错误的原因是您在无限循环中递归自己,所以这是运行时错误。
推荐阅读
- javascript - 在 ReactJS 中,我将如何使用函数而不是类组件重写以下代码?
- javascript - 将选项 id 值传递给控制器并通过 onclick 从另一个刀片视图中检索
- javascript - 如何知道一个字符串是否在Javascript中至少包含一个数组元素
- javascript - NodeJs/Webpack 项目中的工件是什么,我们如何使用它进行 CI/CD?
- ruby - Ruby中矩阵元素的比较
- windows - 删除Windows批处理脚本中除一个文件夹之外的文件夹?
- android - 父 RelativeLayout 中子 LinearLayouts 的百分比(加权)高度
- c# - 使用 raycast2D 并让玩家旋转到 .hit 以防止他们跳跃
- python-3.x - 使用 sql 或 pandas 数据框获取前 5 行的 pyspark 数据框
- php - 使用 Dom PDF 将刀片文件转换为 pdf 时出现问题