i found this flag code online, but i would like to make it loop if the answer is right. any help?
@bot.command(name=’flags’, description=’Play a flag guessing game’)
async def flag_game(ctx:commands.Context):
“””Start a flag guessing game.”””
# Randomly select a flag from the list.
random_flag = random.choice(list(flags.keys()))
<code># Send a "Drawing..." message with an emoji.
drawing_message = await ctx.send("Drawing... :checkered_flag:")
await ctx.reply("Flag Game Started")
await ctx.channel.purge(limit=1)
# Wait for 3 seconds.
await asyncio.sleep(3)
# Edit the message to show the flag.
flag_emoji = flags[random_flag]
embed = discord.Embed(title='Flag Game', description=f"Here is the flag of one of the countries. What is the name of this country?")
embed.add_field(name="Flag:", value=flag_emoji, inline=False)
await drawing_message.edit(content=None, embed=embed)
# Wait for the user's response.
try:
response = await bot.wait_for("message", check=lambda m: m.author == ctx.author, timeout=30.0)
# Check the response, ignoring case.
if response.content.lower() == random_flag.lower():
await ctx.send(f"Congratulations! Correct answer. It's the flag of {random_flag}.")
else:
await ctx.send(f"Sorry, that's not the correct answer. The correct answer is {random_flag}.")
except asyncio.TimeoutError:
await ctx.send("Time for a response has expired. Game over.")
embed.add_field(name="Flag:", value=flag_emoji, inline=False)
await drawing_message.edit(content=None, embed=embed)
else:
return
</code>
<code># Send a "Drawing..." message with an emoji.
drawing_message = await ctx.send("Drawing... :checkered_flag:")
await ctx.reply("Flag Game Started")
await ctx.channel.purge(limit=1)
# Wait for 3 seconds.
await asyncio.sleep(3)
# Edit the message to show the flag.
flag_emoji = flags[random_flag]
embed = discord.Embed(title='Flag Game', description=f"Here is the flag of one of the countries. What is the name of this country?")
embed.add_field(name="Flag:", value=flag_emoji, inline=False)
await drawing_message.edit(content=None, embed=embed)
# Wait for the user's response.
try:
response = await bot.wait_for("message", check=lambda m: m.author == ctx.author, timeout=30.0)
# Check the response, ignoring case.
if response.content.lower() == random_flag.lower():
await ctx.send(f"Congratulations! Correct answer. It's the flag of {random_flag}.")
else:
await ctx.send(f"Sorry, that's not the correct answer. The correct answer is {random_flag}.")
except asyncio.TimeoutError:
await ctx.send("Time for a response has expired. Game over.")
embed.add_field(name="Flag:", value=flag_emoji, inline=False)
await drawing_message.edit(content=None, embed=embed)
else:
return
</code>
# Send a "Drawing..." message with an emoji.
drawing_message = await ctx.send("Drawing... :checkered_flag:")
await ctx.reply("Flag Game Started")
await ctx.channel.purge(limit=1)
# Wait for 3 seconds.
await asyncio.sleep(3)
# Edit the message to show the flag.
flag_emoji = flags[random_flag]
embed = discord.Embed(title='Flag Game', description=f"Here is the flag of one of the countries. What is the name of this country?")
embed.add_field(name="Flag:", value=flag_emoji, inline=False)
await drawing_message.edit(content=None, embed=embed)
# Wait for the user's response.
try:
response = await bot.wait_for("message", check=lambda m: m.author == ctx.author, timeout=30.0)
# Check the response, ignoring case.
if response.content.lower() == random_flag.lower():
await ctx.send(f"Congratulations! Correct answer. It's the flag of {random_flag}.")
else:
await ctx.send(f"Sorry, that's not the correct answer. The correct answer is {random_flag}.")
except asyncio.TimeoutError:
await ctx.send("Time for a response has expired. Game over.")
embed.add_field(name="Flag:", value=flag_emoji, inline=False)
await drawing_message.edit(content=None, embed=embed)
else:
return
it runs perfectly fine, but i would like to make it continuous
New contributor
Usi Ogbeide is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.