如果有人能解释我在这方面出了什么问题,那将是非常有帮助的,下面我已经提供了错误和代码。谢谢:)如果有人能告诉我如何修复它,或者清楚地勾勒出我哪里出了错,那就太好了,我似乎永远也想不出它遗漏了什么,为什么嵌入缺少价值?
Ignoring exception in command ip:
Traceback (most recent call last):
File "C:\Users\*name*\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 83, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\*name*\Desktop\Sanitary SB\Sanitary.py", line 85, in ip
ctx.send(embed=em)
AttributeError: 'str' object has no attribute 'send'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\*name*\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 892, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\*name*\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 797, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\*name*\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 92, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'str' object has no attribute 'send'
@Sanitary.command()
async def ip(self, ctx, *, ipaddr: str = "1.3.3.7"):
r = requests.get(f'http://extreme-ip-lookup.com/json/{ipaddr}')
em = discord.Embed(color=0x00000)
geo = r.json()
fields = [
{'name': 'IP', 'value': geo['query']},
{'name': 'ipType', 'value': geo['ipType']},
{'name': 'Country', 'value': geo['country']},
{'name': 'City', 'value': geo['city']},
{'name': 'Continent', 'value': geo['continent']},
{'name': 'Country', 'value': geo['country']},
{'name': 'IPName', 'value': geo['ipName']},
{'name': 'ISP', 'value': geo['isp']},
{'name': 'Latitute', 'value': geo['lat']},
{'name': 'Longitude', 'value': geo['lon']},
{'name': 'Org', 'value': geo['org']},
{'name': 'Region', 'value': geo['region']},
{'name': 'Status', 'value': geo['status']},
]
for field in fields:
if field['value']:
em.add_field(name=field['name'], value=field['value'], inline=True)
return await ctx.send(embed=em)
```
发布于 2020-03-13 13:31:50
从命令的函数参数中删除self
,这不在类中,所以ctx
实际上是给定的字符串,而且您应该删除*
,因为discord.py中的函数非常不同,并且是按照命令中的空格顺序分配的(如果您使用的是discord.ext.commands
,那么就是这样)。
https://stackoverflow.com/questions/60671406
复制