embedVar不适用于python discord bot

2024-03-29 11:49:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在编写一个discord机器人,并试图创建一个类似于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

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


Tags: 代码命令send机器人embedawaitctxdiscord
1条回答
网友
1楼 · 发布于 2024-03-29 11:49:38

以下是您缺少的内容:

  1. await ctx.send之前的行中缺少)after值
  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)

相关问题 更多 >