【问题标题】:How do I solve the error CommandInvocationError? Trying to make the discord bot send dog pics using hikari如何解决错误 CommandInvocationError?试图让不和谐机器人使用 hikari 发送狗照片
【发布时间】:2022-09-28 01:21:44
【问题描述】:
import lightbulb
import requests

bot = lightbulb.BotApp(token=\"TOKEN\")


@bot.command
@lightbulb.command(\"dog\",\"Dog pictures\")
@lightbulb.implements(lightbulb.SlashCommand)
async def dog(ctx: lightbulb.Context) -> None:
    response = requests.get(\"https://dog.ceo/api/breeds/image/random\")
    image_link = response.json()[\"message\"]
    await ctx.response(image_link)

bot.run()

尝试在不和谐上执行命令时出错

The error

标签: python discord discord.py bots


【解决方案1】:

错误是灯泡中不存在ctx.response

只需将ctx.response 替换为ctx.respond

【讨论】:

  • 如果我使用 ctx.send 或 ctx.reply,也会出现同样的错误,只是说 AttributeError: 'SlashContext' object has no attribute 'send'/'reply'
  • 我编辑了我的答案,
【解决方案2】:

尝试这个

@bot.command
@lightbulb.command("dog","Dog pictures")
@lightbulb.implements(lightbulb.SlashCommand)
async def dog(ctx: lightbulb.Context) -> None:
    response = requests.get("https://dog.ceo/api/breeds/image/random")
    image_link = response.json()["message"]
    await ctx.respone(image_link)

【讨论】:

  • 仍然有同样的错误
猜你喜欢
  • 2021-06-04
  • 2021-11-03
  • 2020-10-01
  • 2022-01-16
  • 1970-01-01
  • 1970-01-01
  • 2018-08-05
  • 2021-04-25
  • 1970-01-01
相关资源
最近更新 更多