discord.py如何在不同的冷却时间下进行不同的工作!工作指令
嗨,伙计们!所以我想让不同的工作与不同的冷却工作下!工作指挥部。我上面给出的代码不起作用。更特殊的是,冷却不起作用。它将做其他它应该做的事情(给用户钱并在频道中发送消息)。我已经尝试了几个星期来解决这个问题。好的,所以很清楚为什么它不起作用。 所以,当用户运行命令时!工作,根据他们的工作,它运行负责工作的功能。不幸的是,由于用户实际上只是运行discord.py如何在不同的冷却时间下进行不同的工作!工作指令,discord.py,Discord.py,嗨,伙计们!所以我想让不同的工作与不同的冷却工作下!工作指挥部。我上面给出的代码不起作用。更特殊的是,冷却不起作用。它将做其他它应该做的事情(给用户钱并在频道中发送消息)。我已经尝试了几个星期来解决这个问题。好的,所以很清楚为什么它不起作用。 所以,当用户运行命令时!工作,根据他们的工作,它运行负责工作的功能。不幸的是,由于用户实际上只是运行work功能,而不是youtuberwork,因此没有应用youtuberwork的冷却。(用户运行的函数运行的是youtuberwork,而不是用户,如果
work
功能,而不是youtuberwork
,因此没有应用youtuberwork
的冷却。(用户运行的函数运行的是youtuberwork,而不是用户,如果用户不使用!work但!youtuberwork等,它将起作用。)
不幸的是,我无法帮助您使用您现在拥有的代码,我不完全确定如何才能运行冷却,但您可以做的是让用户必须运行负责用户工作的actuall命令
前一个“解决方案”的替代方案是在work函数中添加一个check-如果ctx.author在最后X秒内工作过,则通过,否则运行该函数。
虽然,我不建议这样做,但我真的没有一个足够的答案可以帮助你解决这个问题
如前所述,最好的解决方案是让用户运行实际的命令,使其更简单。这是否回答了您的问题?不,这对我似乎不起作用
@client.command(aliases = ["Work", "w", "W"])
async def work(ctx):
await open_account(ctx.author)
users = await getbankdata()
user = ctx.author
job = users[str(user.id)]["job"]
if job == None:
await ctx.send(f"You have no job! Type !jobs for list of jobs and !getjob *jobname* to get a job.")
elif job == "youtuber":
await youtuberwork(ctx, ctx.author)
elif job == "manager":
await managerwork(ctx, ctx.author)
elif job == "receptionist":
await receptionistwork(ctx, ctx.author)
@client.command()
@commands.is_owner()
@cooldown(1, 18000, BucketType.user)
async def youtuberwork(ctx, user):
await open_account(ctx.author)
user = ctx.author
users = await getbankdata()
earnings = 120
users[str(user.id)]["wallet"] += earnings
await ctx.send(f"You Worked as a YouTuber and gained {earnings} coins!")
with open("mainbank.json", "w") as f:
json.dump(users, f)
@client.command()
@commands.is_owner()
@cooldown(1, 19800, BucketType.user)
async def managerwork(ctx, user):
await open_account(ctx.author)
users = await getbankdata()
earnings = 150
users[str(user.id)]["wallet"] += earnings
await ctx.send(f"You Worked as a Manager and gained {earnings} coins!")
with open("mainbank.json", "w") as f:
json.dump(users, f)
@client.command()
@commands.is_owner()
@cooldown(1, 16200, BucketType.user)
async def receptionistwork(ctx, user):
await open_account(ctx.author)
users = await getbankdata()
earnings = 100
users[str(user.id)]["wallet"] += earnings
await ctx.send(f"You Worked as a Receptionist and gained {earnings} coins!")
with open("mainbank.json", "w") as f:
json.dump(users, f)