搜索命令未按预期工作|discord.py



我是经济命令的新手,我仍在研究如何使用bot.wait_for,所以很抱歉这是一个简单的解决方案。所以我正在制作一个搜索命令,但它不起作用。即使在使用代码块键入我想搜索的地方之后,机器人仍然不起作用。图像的

这是代码

@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?")

问题出在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?")

最新更新