【发布时间】:2020-11-02 09:35:23
【问题描述】:
我希望两个用户互相挑战以便能够使用反应,所以如果你只能使用一个命令。
使用命令tfo @user 我希望您向用户发送一条私人消息,并可以单击两个反应之一来接受或拒绝具有时间限制的挑战,以防未及时执行取消挑战请求并将发送另一条私人消息(给你们俩)。
我知道要做到这一点,我应该使用await client.wait_for,但我不知道如何将其用于反应。
这是我用于针对机器人的版本的代码
@client.command(aliases=["TFO"])
async def tenta_la_fortuna_offline(ctx, amount : int):
id = str(ctx.message.author.id)
amounts[id] -= amount
if amounts[id] < 0:
await ctx.send(f"Non hai abbastanza soldi per giocare.")
amounts[id] += amount
return
if amount < 99:
await ctx.send("Puoi puntare da 100 in poi")
return
if not amount:
await ctx.send("Aggiungi quanti soldi vuoi puntare")
return
if id not in amounts:
await ctx.send("Hai bisogno di un account per giocare")
return
utente = [
('Sei salvo!', 'salvo',),
('Sei a rischio eliminazione!', 'rischio',),
('Sei __ELIMINATO__!', 'eliminato'),
('Hai __~~VINTO~~__!', 'vinto'),
('Sei a rischio eliminazione!', 'rischio',),
]
bot = [
('Sei salvo!', 'salvo',),
('Sei a rischio eliminazione!', 'rischio',),
('Sei __ELIMINATO__!', 'eliminato'),
('Hai __~~VINTO~~__!', 'vinto'),
('Sei a rischio eliminazione!', 'rischio',),
]
embed = discord.Embed(
title="**Tenta la Fortuna - Offline**",
description="Affronta il nostro bot per poter vincere il doppio dei soldi scommessi!",
color=0x003399
)
embed.set_thumbnail(url='https://cdn.discordapp.com/attachments/640563710104043530/731596857868025886/TENTA_LA_FORTUNA.png')
embed.add_field(
name="**Utente**",
value="** **",
inline=True
)
embed.add_field(
name="**Bot**",
value="** **",
inline=True
)
message = await ctx.send(embed=embed)
win = int(amount * 2)
await asyncio.sleep(1)
for numero in range(1,101):
u_uscita, u_condizione = random.choice(utente)
embed.clear_fields()
if u_condizione == "eliminato":
embed = discord.Embed(
title="**Tenta la Fortuna - Offline**",
description="Affronta il nostro bot per poter vincere il doppio dei soldi scommessi!",
color=0xFF0000
)
embed.set_thumbnail(
url='https://cdn.discordapp.com/attachments/640563710104043530/731596857868025886/TENTA_LA_FORTUNA.png'
)
embed.set_footer(
text=f"Round numero {numero}"
)
embed.add_field(
name="**Utente**",
value=f"{u_uscita}",
inline=True
)
embed.add_field(
name="**Bot**",
value="** **",
inline=True
)
await message.edit(embed=embed)
return
if u_condizione == "vinto":
embed = discord.Embed(
title="**Tenta la Fortuna - Offline**",
description="Affronta il nostro bot per poter vincere il doppio dei soldi scommessi!",
color=0x00FF00
)
embed.set_thumbnail(
url='https://cdn.discordapp.com/attachments/640563710104043530/731596857868025886/TENTA_LA_FORTUNA.png'
)
embed.set_footer(
text=f"Round numero {numero}"
)
embed.add_field(
name="**Utente**",
value=f"{u_uscita}",
inline=True
)
embed.add_field(
name="**Bot**",
value="** **",
inline=True
)
await message.edit(embed=embed)
amounts[id] += win
return
embed.set_footer(
text=f"Round numero {numero}"
)
embed.add_field(
name="**Utente**",
value=f"{u_uscita}",
inline=True
)
embed.add_field(
name="**Bot**",
value="** **",
inline=True
)
await message.edit(embed=embed)
await asyncio.sleep(0.5)
b_uscita, b_condizione = random.choice(bot)
embed.clear_fields()
if b_condizione == "vinto":
embed = discord.Embed(
title="**Tenta la Fortuna - Offline**",
description="Affronta il nostro bot per poter vincere il doppio dei soldi scommessi!",
color=0xFF0000
)
embed.set_thumbnail(
url='https://cdn.discordapp.com/attachments/640563710104043530/731596857868025886/TENTA_LA_FORTUNA.png'
)
embed.set_footer(
text=f"Round numero {numero}"
)
embed.add_field(
name="**Utente**",
value=f"{u_uscita}",
inline=True
)
embed.add_field(
name="**Bot**",
value=f"{b_uscita}",
inline=True
)
await message.edit(embed=embed)
return
if u_condizione == "rischio":
if b_condizione == "salvo":
embed = discord.Embed(
title="**Tenta la Fortuna - Offline**",
description="Affronta il nostro bot per poter vincere il doppio dei soldi scommessi!",
color=0xFF0000
)
embed.set_thumbnail(
url='https://cdn.discordapp.com/attachments/640563710104043530/731596857868025886/TENTA_LA_FORTUNA.png'
)
embed.set_footer(
text=f"Round numero {numero}"
)
embed.add_field(
name="**Utente**",
value=f"{u_uscita}",
inline=True
)
embed.add_field(
name="**Bot**",
value=f"{b_uscita}",
inline=True
)
await message.edit(embed=embed)
return
if b_condizione == "eliminato":
embed = discord.Embed(
title="**Tenta la Fortuna - Offline**",
description="Affronta il nostro bot per poter vincere il doppio dei soldi scommessi!",
color=0x00FF00
)
embed.set_thumbnail(
url='https://cdn.discordapp.com/attachments/640563710104043530/731596857868025886/TENTA_LA_FORTUNA.png'
)
embed.set_footer(
text=f"Round numero {numero}"
)
embed.add_field(
name="**Utente**",
value=f"{u_uscita}",
inline=True
)
embed.add_field(
name="**Bot**",
value=f"{b_uscita}",
inline=True
)
await message.edit(embed=embed)
amounts[id] += amount
return
if b_condizione == "rischio":
if u_condizione == "salvo":
embed = discord.Embed(
title="**Tenta la Fortuna - Offline**",
description="Affronta il nostro bot per poter vincere il doppio dei soldi scommessi!",
color=0x00FF00
)
embed.set_thumbnail(
url='https://cdn.discordapp.com/attachments/640563710104043530/731596857868025886/TENTA_LA_FORTUNA.png'
)
embed.set_footer(
text=f"Round numero {numero}"
)
embed.add_field(
name="**Utente**",
value=f"{u_uscita}",
inline=True
)
embed.add_field(
name="**Bot**",
value=f"{b_uscita}",
inline=True
)
await message.edit(embed=embed)
amounts[id] += win
return
embed.set_footer(
text=f"Round numero {numero}"
)
embed.add_field(
name="**Utente**",
value=f"{u_uscita}",
inline=True
)
embed.add_field(
name="**Bot**",
value=f"{b_uscita}",
inline=True
)
await message.edit(embed=embed)
await asyncio.sleep(1)
if numero == 100:
embed = discord.Embed(
title="**Tenta la Fortuna - Offline**",
description="Affronta il nostro bot per poter vincere il doppio dei soldi scommessi!",
color=0xDBA901
)
embed.set_thumbnail(
url='https://cdn.discordapp.com/attachments/640563710104043530/731596857868025886/TENTA_LA_FORTUNA.png'
)
embed.set_footer(
text=f"Round numero {numero}"
)
embed.add_field(
name="**Utente**",
value=f"{u_uscita}",
inline=True
)
embed.add_field(
name="**Bot**",
value=f"{b_uscita}",
inline=True
)
await message.edit(embed=embed)
【问题讨论】:
标签: discord.py