python - discord.py 使用字典
问题描述
我正在尝试制作一个不和谐的机器人,其中一个功能是它会编写您必须执行的任务/作业。我这样做是为了让人们可以为其他人编写任务。我怎样才能做到这一点?我所拥有的只是一种编写任务的方法,但没有办法打印它。有人可以帮助我用一种简单的方法为 discord.py 制作这本字典吗?这是我拥有的未完成代码的示例:
elif str(message.content).lower() == ">homeworkadd":
await message.channel.send("Enter the homework subject you want to add. Start your text with '>hs *subject and what to do*'")
elif ">hs" in message.content:
whattodo = str(message.content[4:])
homework.append(whattodo)
await message.channel.send("Your subject and your definition ('{}') have been installed successfully!".format(whattodo))
elif str(message.content).lower() == ">homework":
print(homework)
await message.content.send(homework)```
解决方案
不是一个完整的答案,但我建议您使用至少将作业保存到文件的数据库。如果您的机器人崩溃或您需要重新启动它,那么您将丢失存储在数据库中的所有作业。
我建议您使用数据库,它可以非常简单地设置和编写(查看https://docs.python.org/3/library/sqlite3.html)。它还允许您更好地扩展/添加更多功能。基线是,避免将其保存到字典/列表/等。
推荐阅读
- c - 警告:格式“%p”需要“void *”类型的参数,但参数 3 的类型为“char **”
- clojure - 如何在 clojure 中调用'final G.Run run = g.new Run()'
- javascript - 如何仅更新数组中的单个值
- css - 自定义 CSS 被 bootstrap.css.map 覆盖?
- python - 如何将 x-genericbytedata-octet-stream 转换为某种可读/可管理的格式
- angular - 模块解析失败:意外字符“@”。使用 Angular 6 CLI 为组件获取此错误
- python - Linux 中的 Paramiko 错误:“ImportError:Unable to import a GSS-API/SSPI module”
- union - 如何在 Tableau 中合并多个数据源(数据库和 CSV)
- docusignapi - 无法将文档加载到 Docusign
- rust - 从模块访问外部 crate