在 discord.py 中设置超时?
setTimeout in discord.py?
我有这段代码,我希望它也像 discord.js 中的 setTimeout 函数一样工作,但我不知道如何实现。我希望此代码在嵌入中显示老虎机,并且每次旋转时,第二条消息都会针对它旋转的每个字母进行自我编辑。我有这些参考代码:
https://cdn.discordapp.com/attachments/948236057097416766/954472309748555896/unknown.png
https://cdn.discordapp.com/attachments/948236057097416766/954472151866564678/unknown.png
https://cdn.discordapp.com/attachments/948236057097416766/954472868790546462/unknown.png
https://cdn.discordapp.com/attachments/948236057097416766/954472868790546462/unknown.png
https://cdn.discordapp.com/attachments/948236057097416766/954473890883715092/unknown.png
来自朋友,他使用 .js 这是我的插槽代码:
#slots
@client.command()
async def slot(ctx,amount = None):
await open_account(ctx.author)
if amount == None:
em = discord.Embed(title='ERROR:', description='Please specify a amount you want to put in the slot!', color=0xff0000)
await ctx.send(embed = em)
return
bal = await update_bank(ctx.author)
amount = int(amount)
if amount>bal[0]:
em = discord.Embed(title='ERROR:', description="You don't have enough money!", color=0xff0000)
await ctx.send(embed = em)
return
if amount<10:
em = discord.Embed(title='ERROR:', description="Put a amount of ``10-70`` in the slot machine!", color=0xff0000)
await ctx.send(embed = em)
return
if amount>70:
em = discord.Embed(title='ERROR:', description="Put a amount of ``10-70`` in the slot machine!", color=0xff0000)
await ctx.send(embed = em)
return
final = []
for i in range(3):
a = random.choice([':regional_indicator_x:',':regional_indicator_o:',':regional_indicator_q:',':regional_indicator_g:',':regional_indicator_u:'])
final.append(a)
em3 = discord.Embed(title='Slot:', description=f'{final}', color=0xff000)
em3 = set.Image('https://cdn.discordapp.com/attachments/844618714439483435/954485256021508156/ezgif.com-gif-maker.gif')
await ctx.send(embed = em3)
正如你在最后一行看到的那样,我尝试添加那个插槽 GIF。但我希望它旋转 3 次,然后它下面的消息随之改变......我试图用这个尽可能好地阐明我的目标!
相当于JavaScript的setTimeout
函数的python是time.sleep
。
time.sleep
的用法示例是:
await ctx.send(embed = em)
sleep(200)
await ctx.send(embed = em3)
我有这段代码,我希望它也像 discord.js 中的 setTimeout 函数一样工作,但我不知道如何实现。我希望此代码在嵌入中显示老虎机,并且每次旋转时,第二条消息都会针对它旋转的每个字母进行自我编辑。我有这些参考代码: https://cdn.discordapp.com/attachments/948236057097416766/954472309748555896/unknown.png https://cdn.discordapp.com/attachments/948236057097416766/954472151866564678/unknown.png https://cdn.discordapp.com/attachments/948236057097416766/954472868790546462/unknown.png https://cdn.discordapp.com/attachments/948236057097416766/954472868790546462/unknown.png https://cdn.discordapp.com/attachments/948236057097416766/954473890883715092/unknown.png
来自朋友,他使用 .js 这是我的插槽代码:
#slots
@client.command()
async def slot(ctx,amount = None):
await open_account(ctx.author)
if amount == None:
em = discord.Embed(title='ERROR:', description='Please specify a amount you want to put in the slot!', color=0xff0000)
await ctx.send(embed = em)
return
bal = await update_bank(ctx.author)
amount = int(amount)
if amount>bal[0]:
em = discord.Embed(title='ERROR:', description="You don't have enough money!", color=0xff0000)
await ctx.send(embed = em)
return
if amount<10:
em = discord.Embed(title='ERROR:', description="Put a amount of ``10-70`` in the slot machine!", color=0xff0000)
await ctx.send(embed = em)
return
if amount>70:
em = discord.Embed(title='ERROR:', description="Put a amount of ``10-70`` in the slot machine!", color=0xff0000)
await ctx.send(embed = em)
return
final = []
for i in range(3):
a = random.choice([':regional_indicator_x:',':regional_indicator_o:',':regional_indicator_q:',':regional_indicator_g:',':regional_indicator_u:'])
final.append(a)
em3 = discord.Embed(title='Slot:', description=f'{final}', color=0xff000)
em3 = set.Image('https://cdn.discordapp.com/attachments/844618714439483435/954485256021508156/ezgif.com-gif-maker.gif')
await ctx.send(embed = em3)
正如你在最后一行看到的那样,我尝试添加那个插槽 GIF。但我希望它旋转 3 次,然后它下面的消息随之改变......我试图用这个尽可能好地阐明我的目标!
相当于JavaScript的setTimeout
函数的python是time.sleep
。
time.sleep
的用法示例是:
await ctx.send(embed = em)
sleep(200)
await ctx.send(embed = em3)