问题描述
我目前正在编码一个不和谐的bot,并试图创建一个类似于Dank Memer bot具有的“ pls gayrate”的命令。到目前为止,这是我的代码:
@client.command()
async def gayrate(ctx):
zeroto100 = random.randint(0,100)
embedVar = discord.Embed(title = "gayrate lmao",description = "how gay are ya",color = 0xffffff)
embedVar.add_field(name = f"{message.author}",value = "is",zeroto100,"percent gay :gay_pride_flag:"
await ctx.send (embed = embedVar)
运行此代码时,它返回:
await ctx.send (embed = embedVar)
^
SyntaxError: invalid syntax
我还有其他所有必要的东西来运行机器人,这只是一部分而已。有谁知道如何解决这个问题?谢谢!
解决方法
这是您所缺少的东西:
- 您在
)
之前的行中缺少await ctx.send
之后的值。 - 您应使用
f-strings
进行字符串格式化。 - 应为
ctx.message.author
,而不是message.author
。 - 命令装饰器需要
()
。
这是修改后的代码:
@client.command()
async def gayrate(ctx):
zeroto100 = random.randint(0,100)
embedVar = discord.Embed(title="gayrate lmao",description="how gay are ya",color=0xffffff)
embedVar.add_field(name=f"{ctx.message.author}",value=f"is {zeroto100} percent gay :gay_pride_flag:")
await ctx.send(embed=embedVar)