我猜了一下不和谐机器人中的角色游戏(见下面的代码)。 我想给球员增加30秒的暂停时间,但我完全不知道该怎么做,有什么帮助吗?
@client.command()
async def game(ctx):
chosen_image = random.choice(embedlinks.bnhaLinks)
channel = ctx.channel
index = embedlinks.bnhaLinks.index(chosen_image)
embed = discord.Embed(color=0x999999)
embed.set_image(url=chosen_image)
embed.set_footer(text=f"You have 30 seconds to guess this MHA character")
await ctx.send(embed=embed)
def check(msg):
return msg.author == ctx.author and msg.channel == ctx.channel
user_guess = (await client.wait_for('message', check=check)).content
if user_guess == embedlinks.bnhaChars[index]:
await ctx.send('Correct. Good job.')
elif user_guess is not embedlinks.bnhaChars[index]:
await ctx.send('Wrong. Start a new game.')```
您应该在wait_for
timeout = seconds
条件
@client.command()
async def game(ctx):
chosen_image = random.choice(embedlinks.bnhaLinks)
channel = ctx.channel
index = embedlinks.bnhaLinks.index(chosen_image)
embed = discord.Embed(color=0x999999)
embed.set_image(url=chosen_image)
embed.set_footer(text=f"You have 30 seconds to guess this MHA character")
await ctx.send(embed=embed)
def check(msg):
return msg.author == ctx.author and msg.channel == ctx.channel
user_guess = (await client.wait_for(timeout = 30, 'message', check=check)).content
if user_guess == embedlinks.bnhaChars[index]:
await ctx.send('Correct. Good job.')
elif user_guess is not embedlinks.bnhaChars[index]: #put this if you want user to guess only once and not multiple times
await ctx.send('Wrong. Start a new game.')```
@game.error
async def on_error(self, ctx, error):
if isinstance(error, commands.CommandInvokeError):
await ctx.send("Time is up!")
这篇关于如何添加超时、PYTHON不和机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持吉威生活!
[英文标题]How to add timeout, python discord bot
声明:本媒体部分图片、文章来源于网络,版权归原作者所有,如有侵权,请联系QQ:330946442删除。