【问题标题】:discord.py custom profile with bio带有 bio 的 discord.py 自定义配置文件
【发布时间】:2022-01-15 00:14:34
【问题描述】:

我正在尝试编写一个不和谐的机器人,其中所有用户都有一个可自定义的配置文件。每当他们运行命令!profile 时,机器人都会显示一个嵌入的生物。嵌入将是他们选择的自定义嵌入颜色和其他信息,如他们的硬币等。我想让它每当他们运行!bio test之类的东西时,他们的个人资料嵌入将有消息test,如果他们运行!bio Lorem,他们的自定义个人资料生物将被编辑为Lorem等等。但是,当我尝试执行 !bio test 命令时,它不起作用

def saveJson(data, file):
    json.dump(data, open(file, "w"), indent = 4)

@client.command(aliases=["b"])
async def bio(ctx, *, message):
  user = ctx.author.id
  username = str(ctx.author)
    desciption['users'].append({
      'id':user,
      'name':username,
      'description': [message]
    })
    saveJson(description, "./profile.json")

稍后在 profile 命令中,我的机器人将在 json 文件中找到描述部分,并在有人检查您的个人资料时显示它

【问题讨论】:

  • 这里有什么问题?
  • 我尝试执行 !bio 命令但它不起作用

标签: python json discord profile


【解决方案1】:

变量是description。 你写了""desciption""['users'].append(...

【讨论】:

  • 天哪,我没有注意到错字。但是在我纠正错字后它仍然不起作用?它说意外缩进
  • 可能是因为你留下了缩进-
  • " "description['users'].append({ 'id':user, 'name':username, 'description': [message] })
  • 现在显示未定义的名称描述,我应该添加类似 description=message 的内容吗?
  • 您可以在开头初始化一个新字典,因此 description={} 在文件开头
猜你喜欢
  • 1970-01-01
  • 2014-05-04
  • 1970-01-01
  • 2017-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-11
相关资源
最近更新 更多