首页 > 解决方案 > embedVar 不适用于 python discord bot

问题描述

我目前正在编写一个不和谐的机器人,并试图创建一个类似于 Dank Memer 机器人的“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

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

标签: pythondiscorddiscord.py

解决方案


以下是您缺少的内容:

  1. )在 before 行缺少 after 值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)

推荐阅读