搜索命令无法正常工作不和谐

时间:2020-11-02 06:10:33

标签: discord.py

我是经济指挥机构的新手,但我仍在寻找如何使用bot.wait_for的功能,所以很抱歉,这很简单。因此,我正在执行搜索命令,但是它不起作用。即使在使用代码块键入我想搜索的位置后,该机器人仍然无法正常工作。 Image's

这是代码

  @commands.command()
  async def search(self, ctx):
    await open_account(ctx.author)

    place = [f'`couch`', f"`park`", f"`road`"]
    place1 = [f"`dog`", f"`tree`", "`car`"]
    place2 = [f"`discord`", f"`grass`", f"`pocket`"]

    await ctx.send(f"Where do you wanna search? Pick from the list below.\n {random.choice(place)},{random.choice(place1)}, {random.choice(place2)}")
    
    answer = await self.bot.wait_for('message', check=lambda message: message.author == ctx.author)

    if answer.content.lower() == place or answer.content == place1 or answer.content == place2:
      earnings = random.randrange(301)
      await update_bank(ctx.author, earnings, "wallet")
      await ctx.send(f"You just found {earnings} coins. Cool")
      return
    else:
      await ctx.send("Thats not a part of the list tho?")

1 个答案:

答案 0 :(得分:0)

您的if语句是问题所在。您正在检查输入的单词是否等于列表之一。您应该列出可用单词的列表,然后检查给定单词是否在该列表中:

@client.command()
async def search(ctx):

    place1 = ["couch", "park", "road"]
    place2 = ["dog", "tree", "car"]
    place3 = ["discord", "grass", "pocket"]

    places = [random.choice(place1), random.choice(place2), random.choice(place3)]
    placesToSearch = ', '.join([f"`{x.title()}`" for x in places])

    await ctx.send(f"Where do you wanna search? Pick from the list below.\n {placesToSearch}")
    response = await client.wait_for('message', check=lambda message: message.author == ctx.author)

    if response.content.lower() in places:
        earnings = random.randrange(301)
        await ctx.send(f"You just found {earnings} coins. Cool")
    else:
        await ctx.send("Thats not a part of the list tho?")