【发布时间】:2021-01-30 20:27:04
【问题描述】:
我想在 python 命令中创建一个不和谐机器人,它可以启动一个游戏,你必须在其中写一个给定的单词,一旦用户正确拼写就停止,但 return 在我的情况下不起作用
async def joc(ctx):
a=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'0','1','2','3','4','5','6','7','8','9']
cuv=random.sample(a,10)
cuvant=''
for x in cuv:
cuvant+=x
await ctx.send('The game begins in: ')
await ctx.send('3')
time.sleep(1)
await ctx.send('2')
time.sleep(1)
await ctx.send('1')
time.sleep(1)
await ctx.send('Start!')
await ctx.send(cuvant)
@bot.event
async def on_message(message):
if message.content==cuvant:
await message.channel.send(message.author)
await message.channel.send("Nice")
return
return
我可以通过访问历史来做到这一点,但我想知道如何做到这一点
【问题讨论】:
-
如果你想停止程序,然后使用
exit()退出,如果你想让它再次重复,那么你可以在while True:循环中编写所有工作代码。跨度> -
我只想退出这个函数,如果他们再次调用它再次执行它
-
然后在末尾使用
break
标签: python python-3.x discord bots discord.py