python - Discord.py v3(重写)尝试将用户输入与预设元组列表匹配
问题描述
为我所在的一些 RP 服务器处理不和谐的字符表机器人。我正在添加一个区域以在收集字符信息后编辑字符信息。我有一个为信息收集的初始循环预定义的元组列表,但对于编辑功能,我试图让用户输入与这些预定义元组之一匹配。我不知道......我究竟需要转向哪里?就像,我可以看到我正在尝试做的事情的逻辑,但我在 python 方面的经验水平几乎为零。
在当前时间点,我只是在运行一系列 if/then 语句,但我想让代码循环遍历我拥有的信息收集代码,直到用户告诉机器人他们已经完成编辑,现在每次他们想要编辑时都必须触发机器人。
@commands.command()
async def edit(self, ctx):
def check(message):
return message.author == ctx.message.author
member = ctx.author
n = await self.config.member(member).name()
await ctx.send("Accessing Character Data for {}. . .".format(n))
await asyncio.sleep(1)
await ctx.send("1: Name \n 2: Race \n 3: Gender \n 4: Age \n 5: World of Origin \n 6: Profession/Class/Occupation \n 7: Eyes \n 8: Hair \n 9: Height \n 10: Weight \n 11: Body Mods \n 12: Description \n 13: Primary Weapon \n 14: Secondary Weapon \n 15: Magic/Tech Skill 1 \n 16: Magic/Tech Skill 2 \n 17:Magic/Tech Skill 3 \n 18: Magic/Tech Skill 4 \n 19: Magic/Tech Skill 5 \n 20: Equipped Weapon(s) \n 21: Equipped Armor \n 22: Combat Role")
i = 0
while i == 0:
await ctx.send("Which trait would you like to edit? Please only respond with the numerical value for the selected trait.")
try:
input = await self.bot.wait_for('message', check=check, timeout=60)
except asyncio.TimeoutError:
return
input = input.content
ii = 0
while ii == 0:
if input == "1":
info_type = ("name", "Name")
await self.add_char_info(ctx, info_type, member)
await ctx.send("Would you like to edit another trait?")
try:
msg = await self.bot.wait_for('message', check=check, timeout=60)
except asynico.TimeoutError:
await ctx.send("You took too long to respond. Terminating.")
i = 1
ii = 1
return
msg = msg.content.lower()
if msg == "yes":
ii = 0
elif msg == "no":
i = 1
ii = 1
await ctx.send("Closing Character Editor")
else:
await ctx.send("Please enter yes or no.")
add_char_info(ctx, info_type, member)
指我的信息收集循环,如有必要,我可以发布
因为我现在有代码,它的功能正常,这更像是一种寻求帮助,让它做我真正想要它做的事情,x
即x
根据给定菜单,然后将该输入值与预定义的元组列表中的正确元组匹配。
解决方案
您可以考虑使用 adictionary
来存储您的用户响应x
askeys
并将您的元组存储为values
您希望在用户响应与字典键匹配后执行的操作。
如何在 Python 中使用字典是一个很好的起点
推荐阅读
- javascript - 将全局附加到 Vue 实例
- node.js - 在 Firebase Admin 中验证无密码电子邮件注册
- intellij-idea - 如何在 IntelliJ 中过滤 UML 图以仅显示特定类及其传递依赖项?
- apache - htaccess 404 仅适用于文件级别,但不适用于文件夹级别
- reactjs - 在 ReactJS 中自动将添加的数据反映到表中
- android - 用于 Android 崩溃的 ML-Kit
- javascript - 在 JavaScript 中,我似乎无法为布尔值是否为真/假做出 if 语句
- react-native - > 任务:react-native-wifi-reborn:compileDebugJavaWithJavac FAILED (React-Native)
- android - 切换夜间模式和媒体播放器停止后应用程序崩溃
- mysql - 我想在表格中找到所有关于第二高薪水的记录,并且有许多薪水第二高的员工如何做到这一点