【发布时间】:2021-01-08 11:38:37
【问题描述】:
我正在执行 pls search 类型的命令,但我不知道如何让机器人说出类似“你找到了 [50 - 3000 个随机数量的硬币] 硬币!”之类的话。在我输入问题的答案后。我也不知道如何使 3 个 [random_place] 不一样。所以基本上我希望机器人这样做:
我:请搜索
bot:“你想在哪里搜索?[random_place#1]、[random_place#2]、[random_place#3]”
我:[random_place#1]
bot:“你找到了 [50 - 3000 随机数量的硬币]!”
我尝试使用 on_message 在@client.command 中使用@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}')
【问题讨论】:
标签: discord.py