discord.py - 搜索命令未按预期工作 | 不和谐.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?")
推荐阅读
- tor - 如何更改torrc中的中间节点位置?
- mysql - 在 MySQL 中将 UTC 格式的日期时间转换为 GMT+7
- applescript - 如何制作每次打开时都不征求许可的脚本
- c++ - 如何使用双指针在类中的变量中赋值?
- javascript - 检查元素是否显示:块,不工作
- selenium - 如何通过 Selenium Java 处理 Chrome 浏览器上的允许弹出窗口
- python - 工作管道上的 GridSearchCV 返回 ValueError
- angular - 显示角度反应形式的错误消息的最佳方法,一个表单控制多个验证错误?
- sql - 在最近的记录之前选择记录
- botframework - 使用 MS who bot 在 Teams 之外