python - 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
我有所有其他必要的东西来运行机器人工作,只是这部分不是。有谁知道如何解决这个问题?谢谢!
解决方案
以下是您缺少的内容:
- 您
)
在 before 行缺少 after 值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)
推荐阅读
- r - 如何根据条件消除匹配模式
- javascript - 如果单选按钮未选中,则使用 JavaScript 自动检查另一个单选按钮
- python - 尚不清楚“GridSearchCV”函数如何分解训练集和测试集
- javascript - Ionic 3 键盘盖(覆盖) 聚焦离子输入元件
- wpf - 仅当单击另一个按钮时才启用按钮 wpf datagrid
- cumulocity - 需要互连传感器工作的示例,即当一个传感器触发另一个传感器的动作/工作时
- python - 如何对具有两个返回值的函数进行单元测试?
- javascript - Spring and Angular - 非常简单的 REST 请求
- php - woocommerce 页面中的管理员通知显示
- c# - 自 Windows 更新以来,KeyInfo 无法加载