首页 > 解决方案 > 如何在 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")

标签: pythondiscord.py

解决方案


函数一到达返回就结束,不管值是 False 还是 None,检查总是会返回第一个语句,这里是固定代码

def check(message):
    return message.content in ['1', '2', '3', '4', '5', '6']

推荐阅读