尝试在命令中重新加载 api 但在调试中出现一些错误
Trying to relaod api inside command but getting some errors in debug
@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
每当我使用该命令时,我都会在调试中遇到此错误,但该命令工作正常,我认为这是因为它试图在循环中删除,这就是为什么刷新 API 的更好方法然后去做?
您的问题是 await ctx.message.delete()
行 - 在 while
循环的第一次迭代期间,原始命令消息将被删除。这意味着它不再可用,并且从第二次迭代开始,尝试再次删除它会导致您看到的错误,因为该消息不再存在。您可以通过简单地将 await ctx.message.delete()
行移动到 while
循环
之外来解决这个问题
@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
每当我使用该命令时,我都会在调试中遇到此错误,但该命令工作正常,我认为这是因为它试图在循环中删除,这就是为什么刷新 API 的更好方法然后去做?
您的问题是 await ctx.message.delete()
行 - 在 while
循环的第一次迭代期间,原始命令消息将被删除。这意味着它不再可用,并且从第二次迭代开始,尝试再次删除它会导致您看到的错误,因为该消息不再存在。您可以通过简单地将 await ctx.message.delete()
行移动到 while
循环