python - 如何在 discord.py 上的 wait_for 中使用多个检查
问题描述
我正在尝试在 discord.py 上制作一款游戏,让您可以选择多个选项。每个选项都有不同的作用,它会在开始时发出一个列表,列出要做什么。当我将命令输入到不和谐中时,它遇到了允许这样做的问题,并且说“arg是缺少的必需参数”。正在做我想做的事吗?这是我的代码:
@client.command(description="The Sword Game", name="Sword Sim", aliases=["sg", "sword", "sword-game"])
async def SwordGame(ctx, arg):
embed = discord.Embed(
title='Sword Simulator Game',
Description="The Sword Simulator game by MrPenguin280",
color=discord.Color.dark_red()
)
choiceslist='''
1 = Battle
2 = Check Sword Stats
3 = Check Player Stats
4 = Heal
5 = Power up Magic
6 = XP farm
7 = Leave Sim
'''
embed.add_field(name='Choices:\n', value=choiceslist)
embed.add_field(name='What do you choose?', value="Type it below")
await ctx.send(embed=embed)
def check(m):
return m.content == "1"
return m.content == "7"
return m.content == "2"
return m.content == "3"
return m.content == "4"
return m.content == "5"
return m.content == "6"
msg = await client.wait_for("message", check=check)
if msg == "1":
await ctx.send("You picked to battle")
解决方案
函数一到达返回就结束,不管值是 False 还是 None,检查总是会返回第一个语句,这里是固定代码
def check(message):
return message.content in ['1', '2', '3', '4', '5', '6']
推荐阅读
- pip - pipenv 不会安装其他 git 依赖项引用的 git 依赖项
- flutter - 错误:'RxList 类型的值
' 不能分配给 'List 类型的变量 ' - python - 比较两个字符串并替换字母
- mysql - 预过滤查询
- c# - 对多个 api 控制器的 Jmeter 负载测试
- python - Python - 在函数调用期间检测星号(*)
- html - Angular - 如何放置一个对象
在 BehaviorSubject 中 - java - 如何仅记录来自 WebClient 的 POST ant PATCH 请求
- css - 如何使用 CSS(在 Firefox 中)仅隐藏垂直滚动条?
- reactjs - 我的数据测试 ID 在那里,但我的测试找不到它反应酶开玩笑单元测试