为什么 'str' 没有属性 'name' (PyCharm 2020.3.2 Python 3.9)
Why doesn't 'str' have an attribute 'name' (PyCharm 2020.3.2 Python 3.9)
我做了一个假的 hack 命令(完全由我自己),但是当我在聊天中输入命令时,出现错误提示 str
没有属性 member.name
代码:
@commands.command()
async def hack(self, ctx, member):
random_id = [
"20390940",
"20930948",
"09479398",
"03984988",
"94883099",
"98477490",
"37729902",
"98765421",
"93893893",
"08589498",
"88489920",
"84990201",
"94789435",
"98839897",
"49732974",
"97398394",
"80489033",
"98479883",
"97878820",
"08839004",
"98308934"
]
async def f():
while True:
await ctx.send('Test')
await ctx.send(f" Hacking {member.name}") #Here is the error
task = asyncio.create_task(f())
await asyncio.sleep(5)
await ctx.send("❌ Firewall blocking access")
await asyncio.sleep(5)
await ctx.send("✔ Firewall hacked")
await asyncio.sleep(5)
await ctx.send(f" Apple Account password is {random_id}")
await asyncio.sleep(5)
await ctx.send(f"〽 Credit Card ID is {random_id}")
await asyncio.sleep(5)
await ctx.send(f" Discord ID is {ranid}")
await asyncio.sleep(5)
await ctx.send(" Covering all traces")
await asyncio.sleep(5)
await ctx.send(" Destroying browser memory")
await asyncio.sleep(5)
await ctx.send(f"✔ Finished hacking {member.name}") #Here is also the error
task.cancel()
您可以使用转换器来传递参数。现在,member
参数是一个字符串值,这就是您得到 AttributeError
的原因。您必须将字符串转换为 discord.Member
对象。你可以简单地做:
@commands.command()
async def hack(self, ctx, member: discord.Member):
...
我做了一个假的 hack 命令(完全由我自己),但是当我在聊天中输入命令时,出现错误提示 str
没有属性 member.name
代码:
@commands.command()
async def hack(self, ctx, member):
random_id = [
"20390940",
"20930948",
"09479398",
"03984988",
"94883099",
"98477490",
"37729902",
"98765421",
"93893893",
"08589498",
"88489920",
"84990201",
"94789435",
"98839897",
"49732974",
"97398394",
"80489033",
"98479883",
"97878820",
"08839004",
"98308934"
]
async def f():
while True:
await ctx.send('Test')
await ctx.send(f" Hacking {member.name}") #Here is the error
task = asyncio.create_task(f())
await asyncio.sleep(5)
await ctx.send("❌ Firewall blocking access")
await asyncio.sleep(5)
await ctx.send("✔ Firewall hacked")
await asyncio.sleep(5)
await ctx.send(f" Apple Account password is {random_id}")
await asyncio.sleep(5)
await ctx.send(f"〽 Credit Card ID is {random_id}")
await asyncio.sleep(5)
await ctx.send(f" Discord ID is {ranid}")
await asyncio.sleep(5)
await ctx.send(" Covering all traces")
await asyncio.sleep(5)
await ctx.send(" Destroying browser memory")
await asyncio.sleep(5)
await ctx.send(f"✔ Finished hacking {member.name}") #Here is also the error
task.cancel()
您可以使用转换器来传递参数。现在,member
参数是一个字符串值,这就是您得到 AttributeError
的原因。您必须将字符串转换为 discord.Member
对象。你可以简单地做:
@commands.command()
async def hack(self, ctx, member: discord.Member):
...