Home > Software engineering >  Trying to relaod api inside command but getting some errors in debug
Trying to relaod api inside command but getting some errors in debug

Time:02-10

@client.command() 
async def eth(ctx):
  while True:
    r = requests.request("GET", eth_api, headers=headers)
    data2 = r.json()
    eth_price = data2['data']['rates']['USD']
    await ctx.message.delete()
    await ctx.send(f"The price of ETH is {eth_price}$")
    sleep(0.2)
Ignoring exception in command eth:
Traceback (most recent call last):
  File "/home/runner/Elon-Musk/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "main.py", line 35, in eth
    await ctx.message.delete()
  File "/home/runner/Elon-Musk/venv/lib/python3.8/site-packages/discord/message.py", line 1023, in delete
    await self._state.http.delete_message(self.channel.id, self.id)
  File "/home/runner/Elon-Musk/venv/lib/python3.8/site-packages/discord/http.py", line 250, in request
    raise NotFound(r, data)
discord.errors.NotFound: 404 Not Found (error code: 10008): Unknown Message

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/runner/Elon-Musk/venv/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "/home/runner/Elon-Musk/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/home/runner/Elon-Musk/venv/lib/python3.8/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: NotFound: 404 Not Found (error code: 10008): Unknown Message

I am getting this error in debug whenever i use the command but the command is working fine, i think it's because it's trying to delete in a loop that's why, any better way to refresh API's and do it?

CodePudding user response:

  •  Tags:  
  • Related