在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 次,然后它下面的消息随之改变...我试图尽可能地阐明我的目标!
I have this code and i want it too work like a setTimeout function in discord.js but i dont know how. I want this code to show a slot machine in the embed and every time it spins, the second message edits itself for every letter it spins. I have these reference codes:
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
from a friend and he uses .js This is my code for slots:
#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)
as you can see on the last line i try to add that slots GIF. But i want it to spin 3 times and then the messages under it changes with it... I tried to clarify my goal with this a good as possible!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
相当于 JavaScript 的
setTimeout
函数的 python 是time.sleep
。time.sleep
的一个示例用法是:The python equivalent to JavaScript's
setTimeout
function istime.sleep
.An example usage of
time.sleep
is: