embedVar在python discord bot上不起作用

问题描述

我目前正在编码一个不和谐的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

我还有其他所有必要的东西来运行机器人,这只是一部分而已。有谁知道如何解决这个问题?谢谢!

解决方法

这是您所缺少的东西:

  1. 您在)之前的行中缺少await ctx.send之后的值。
  2. 您应使用f-strings进行字符串格式化。
  3. 应为ctx.message.author,而不是message.author
  4. 命令装饰器需要()

这是修改后的代码:

@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)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...