Discord.py 如何停止制造不和谐机器人询问某个问题,然后当我键入某个内容时,命令停止,以便我可以';不要发垃圾邮件

Discord.py 如何停止制造不和谐机器人询问某个问题,然后当我键入某个内容时,命令停止,以便我可以';不要发垃圾邮件,discord.py,Discord.py,我正在做一个pls搜索类型的命令,但我不知道如何让机器人在我键入一个问题的答案后说“你找到了(50-3000)个硬币的随机数量!”之类的话。我也不知道如何使3个[随机位置]不一样。所以基本上我希望机器人能做到这一点: 我:请搜索 机器人:“你想在哪里搜索?[随机地点1],[随机地点2],[随机地点3]” 我:[随机地点1] 机器人:“你发现了[随机数量的50-3000]枚硬币!” 我尝试在@client.command中使用on_消息使用@client.event,但当我尝试测试它时,我能够发送

我正在做一个pls搜索类型的命令,但我不知道如何让机器人在我键入一个问题的答案后说“你找到了(50-3000)个硬币的随机数量!”之类的话。我也不知道如何使3个[随机位置]不一样。所以基本上我希望机器人能做到这一点:

我:请搜索

机器人:“你想在哪里搜索?[随机地点1],[随机地点2],[随机地点3]”

我:[随机地点1]

机器人:“你发现了[随机数量的50-3000]枚硬币!”

我尝试在@client.command中使用on_消息使用@client.event,但当我尝试测试它时,我能够发送垃圾邮件并获得无限硬币。我该如何解决这个问题?这是我的代码:

@client.command()
async def search(ctx):
  search_list = {
  "Sewer": f'You searched the sewer and found {amount_of_coins_found} coins!',
  'Area51': f'You raided Area51 and found {amount_of_coins_found} coins! NOW RUN THE GOVERNMENT IS CHASING YOU!',
  'Tree': f'You climbed the tree and found {amount_of_coins_found} coins! Good thing you didn\'t fall off and break your neck.',
  'Dog': f'You pet the dog and found {amount_of_coins_found} coins! That poor poor dog...',
  'Street': f'You searched the street and found {amount_of_coins_found} coins! Good thing you didn\'t get run over by a bus!',
  'Hospital': f'You searched the hospital and found {amount_of_coins_found} coins! Did you steal from a sick person?!',
  'Dumpster': f'You climbed inside the dumpster and found {amount_of_coins_found} coins! Good thing the garbage truck only comes on Thursdays.',
  'Air': f'You searched the air and found {amount_of_coins_found} coins!',
  'Attic': f'You searched the attic and found {amount_of_coins_found} coins!',
  'Bank': f'',
  'Bed': f'',
  'Bus': f'',
  'Bushes': f'',
  'Uber': f'',
  'Car': f'',
  'Coat': f'',
  'Couch': f'',
  'Discord': f'',
  'Dresser': f'',
  'Laundromat': f'',
  'Mailbox': f'',
  'Pocket': f'',
  'Purse': f'',
  'Grass': f'',
  'Pantry': f'',
  'Shoe': f'',
  'Sink': f'',
  'Pumpkin': f''
  }
  a = random.choice(list(search_list.keys()))
  b = random.choice(list(search_list.keys()))
  c = random.choice(list(search_list.keys()))
  sameness = True
  while sameness == True:
      a = random.choice(list(search_list.keys()))
      b = random.choice(list(search_list.keys()))
      c = random.choice(list(search_list.keys()))
  if a != b or a != c or b != c:
    sameness=False
    await ctx.send(f"<@{ctx.author.id}> Where do you want to search?\n Pick from the list below and type it in the chat:\n`{a}`, `{b}`, `{c}`")
    @client.event
    async def on_message(message):
      if message.author == client.user:
        return

      if message.content.startswith(f'{a}'):
        await message.channel.send(f'{a.value}')
      if message.content.startswith(f'{b}'):
        await message.channel.send(f'{b.value}')
      if message.content.startswith(f'{c}'):
        await message.channel.send(f'{c.value}')
@client.command()
异步def搜索(ctx):
搜索列表={
“下水道”:如果你搜索了下水道,发现了{硬币的数量}硬币!',
“Area51”:f'You突击搜查了Area51,发现了{amount_of_coins_found}硬币!现在快跑,政府在追你!“,
“树”:如果你爬到树上发现了{硬币的数量}硬币!幸好你没有摔下来摔断脖子,
“狗”:如果你抚摸这只狗,发现了{硬币的数量}硬币!那只可怜的狗,
“Street”:如果你在街上搜索发现了{硬币的数量}硬币!幸好你没有被公共汽车辗过,
“医院”:如果你搜查了医院,发现了{硬币的数量}硬币!你偷了一个病人的东西吗,
“垃圾箱”:如果你爬进垃圾箱,发现了{硬币数量}硬币!幸好垃圾车只在星期四来,
“空气”:f“你搜索了空气,发现了{硬币的数量}硬币!”,
“阁楼”:f“你搜索了阁楼,发现了{硬币的数量}硬币!”,
“银行”:f“”,
“床”:f“”,
“总线”:f“”,
“灌木丛”:f“”,
“Uber”:f',
'Car':f',
“Coat”:f“”,
'沙发':f',
'Discord':f',
“Dresser”:f“”,
“自助洗衣店”:f“”,
“邮箱”:f“”,
“Pocket”:f“”,
“钱包”:f“”,
'草':f',
“食品储藏室”:f“”,
'Shoe':f',
“接收器”:f“”,
“南瓜”:f“
}
a=随机.choice(list(search\u list.keys()))
b=random.choice(list(search\u list.keys()))
c=random.choice(list(search\u list.keys()))
相同=真实
而相同性==真:
a=随机.choice(list(search\u list.keys()))
b=random.choice(list(search\u list.keys()))
c=random.choice(list(search\u list.keys()))
如果是b还是a!=c或b!=c:
相同=错误
等待ctx.send(f“您想在哪里搜索?\n从下面的列表中选择并在聊天中键入:\n`{a}`、`{b}`、`{c}`”)
@客户端事件
异步def on_消息(消息):
如果message.author==client.user:
返回
如果message.content.startswith(f'{a}'):
等待message.channel.send(f'{a.value}')
如果message.content.startswith(f'{b}'):
等待message.channel.send(f'{b.value}')
如果message.content.startswith(f'{c}'):
wait message.channel.send(f'{c.value}')
random\u place
变量将保存搜索目录中的3个随机位置。
下一行将发送“你想在哪里搜索?”<代码>1,
2
3

现在我使用函数等待用户输入。如果用户发送了一条消息,它将开始检查正确的
位置(1,2,3)
、频道和用户,

如果一切正常,它将发送所选位置的
搜索目录

运行时,您的on_消息将是全局的,并且贯穿整个bot,这意味着如果有人说出这些特定的关键字,即使命令未运行,他们也会得到硬币

您也不能像以前一样在命令中使用事件,只需使用如下所示的检查:

message = await client.wait_for('message', timeout=10, check=lambda message: message.author == ctx.author)


      if message.content.startswith(f'{a}'):
        await message.channel.send(f'{a.value}')
      if message.content.startswith(f'{b}'):
        await message.channel.send(f'{b.value}')
      if message.content.startswith(f'{c}'):
        await message.channel.send(f'{c.value}')

只需将此更改为您想要的方式,希望这对您有所帮助

@client.command()
async def search(ctx):
  search_list = {
  "Sewer": f'You searched the sewer and found {amount_of_coins_found} coins!',
  'Area51': f'You raided Area51 and found {amount_of_coins_found} coins! NOW RUN THE GOVERNMENT IS CHASING YOU!',
  'Tree': f'You climbed the tree and found {amount_of_coins_found} coins! Good thing you didn\'t fall off and break your neck.',
  'Dog': f'You pet the dog and found {amount_of_coins_found} coins! That poor poor dog...',
  'Street': f'You searched the street and found {amount_of_coins_found} coins! Good thing you didn\'t get run over by a bus!',
  'Hospital': f'You searched the hospital and found {amount_of_coins_found} coins! Did you steal from a sick person?!',
  'Dumpster': f'You climbed inside the dumpster and found {amount_of_coins_found} coins! Good thing the garbage truck only comes on Thursdays.',
  'Air': f'You searched the air and found {amount_of_coins_found} coins!',
  'Attic': f'You searched the attic and found {amount_of_coins_found} coins!',
  'Bank': f'',
  'Bed': f'',
  'Bus': f'',
  'Bushes': f'',
  'Uber': f'',
  'Car': f'',
  'Coat': f'',
  'Couch': f'',
  'Discord': f'',
  'Dresser': f'',
  'Laundromat': f'',
  'Mailbox': f'',
  'Pocket': f'',
  'Purse': f'',
  'Grass': f'',
  'Pantry': f'',
  'Shoe': f'',
  'Sink': f'',
  'Pumpkin': f''
  }
  a = random.choice(list(search_list.keys()))
  b = random.choice(list(search_list.keys()))
  c = random.choice(list(search_list.keys()))
  sameness = True
  while sameness == True:
      a = random.choice(list(search_list.keys()))
      b = random.choice(list(search_list.keys()))
      c = random.choice(list(search_list.keys()))
  if a != b or a != c or b != c:
    sameness=False
    await ctx.send(f"<@{ctx.author.id}> Where do you want to search?\n Pick from the list below and type it in the chat:\n`{a}`, `{b}`, `{c}`")

message = await client.wait_for('message', timeout=10, check=lambda message: message.author == ctx.author)


      if message.content.startswith(f'{a}'):
        await message.channel.send(f'{a.value}')
      if message.content.startswith(f'{b}'):
        await message.channel.send(f'{b.value}')
      if message.content.startswith(f'{c}'):
        await message.channel.send(f'{c.value}')

@client.command()
异步def搜索(ctx):
搜索列表={
“下水道”:如果你搜索了下水道,发现了{硬币的数量}硬币!',
“Area51”:f'You突击搜查了Area51,发现了{amount_of_coins_found}硬币!现在快跑,政府在追你!“,
“树”:如果你爬到树上发现了{硬币的数量}硬币!幸好你没有摔下来摔断脖子,
“狗”:如果你抚摸这只狗,发现了{硬币的数量}硬币!那只可怜的狗,
“Street”:如果你在街上搜索发现了{硬币的数量}硬币!幸好你没有被公共汽车辗过,
“医院”:如果你搜查了医院,发现了{硬币的数量}硬币!你偷了一个病人的东西吗,
“垃圾箱”:如果你爬进垃圾箱,发现了{硬币数量}硬币!幸好垃圾车只在星期四来,
“空气”:f“你搜索了空气,发现了{硬币的数量}硬币!”,
“阁楼”:f“你搜索了阁楼,发现了{硬币的数量}硬币!”,
“银行”:f“”,
“床”:f“”,
“总线”:f“”,
“灌木丛”:f“”,
“Uber”:f',
'Car':f',
“Coat”:f“”,
'沙发':f',
'Discord':f',
“Dresser”:f“”,
“自助洗衣店”:f“”,
“邮箱”:f“”,
“Pocket”:f“”,
“钱包”:f“”,
'草':f',
“食品储藏室”:f“”,
'Shoe':f',
“接收器”:f“”,
“南瓜”:f“
}
a=随机.choice(list(search\u list.keys()))
b=random.choice(list(search\u list.keys()))
c=random.choice(list(search\u list.keys()))
相同=真实
而相同性==真:
a=随机.choice(list(search\u list.keys()))
b=random.choice(list(search\u list.keys()))
c=random.choice(list(search\u list.keys()))
如果是b还是a!=c或b!=c:
相同=错误
等待ctx.send(f“您想在哪里搜索?\n从下面的列表中选择并在聊天中键入:\n`{a}`、`{b}`、`{c}`”)
message=wait client.wait_for('message',timeout=10,check=lambda message:message.author==ctx.author)
如果message.content.startswith(f'{a}'):
等待message.channel.send(f'{a.value
@client.command()
async def search(ctx):
  search_list = {
  "Sewer": f'You searched the sewer and found {amount_of_coins_found} coins!',
  'Area51': f'You raided Area51 and found {amount_of_coins_found} coins! NOW RUN THE GOVERNMENT IS CHASING YOU!',
  'Tree': f'You climbed the tree and found {amount_of_coins_found} coins! Good thing you didn\'t fall off and break your neck.',
  'Dog': f'You pet the dog and found {amount_of_coins_found} coins! That poor poor dog...',
  'Street': f'You searched the street and found {amount_of_coins_found} coins! Good thing you didn\'t get run over by a bus!',
  'Hospital': f'You searched the hospital and found {amount_of_coins_found} coins! Did you steal from a sick person?!',
  'Dumpster': f'You climbed inside the dumpster and found {amount_of_coins_found} coins! Good thing the garbage truck only comes on Thursdays.',
  'Air': f'You searched the air and found {amount_of_coins_found} coins!',
  'Attic': f'You searched the attic and found {amount_of_coins_found} coins!',
  'Bank': f'',
  'Bed': f'',
  'Bus': f'',
  'Bushes': f'',
  'Uber': f'',
  'Car': f'',
  'Coat': f'',
  'Couch': f'',
  'Discord': f'',
  'Dresser': f'',
  'Laundromat': f'',
  'Mailbox': f'',
  'Pocket': f'',
  'Purse': f'',
  'Grass': f'',
  'Pantry': f'',
  'Shoe': f'',
  'Sink': f'',
  'Pumpkin': f''
  }
  a = random.choice(list(search_list.keys()))
  b = random.choice(list(search_list.keys()))
  c = random.choice(list(search_list.keys()))
  sameness = True
  while sameness == True:
      a = random.choice(list(search_list.keys()))
      b = random.choice(list(search_list.keys()))
      c = random.choice(list(search_list.keys()))
  if a != b or a != c or b != c:
    sameness=False
    await ctx.send(f"<@{ctx.author.id}> Where do you want to search?\n Pick from the list below and type it in the chat:\n`{a}`, `{b}`, `{c}`")

message = await client.wait_for('message', timeout=10, check=lambda message: message.author == ctx.author)


      if message.content.startswith(f'{a}'):
        await message.channel.send(f'{a.value}')
      if message.content.startswith(f'{b}'):
        await message.channel.send(f'{b.value}')
      if message.content.startswith(f'{c}'):
        await message.channel.send(f'{c.value}')