【发布时间】:2021-06-12 04:30:46
【问题描述】:
我一直在尝试编写一个碰撞提醒/停止 disboard 在那段时间内处理命令,并且没有任何与我在互联网上可以找到的类似的东西: 我当前的代码是:
async def bump_reminder(ctx: discord.ext.commands.Context, action: str):
disboard=ctx.guild.get_member(302050872383242240)
if ctx.channel.id!=852646981759270972 :
await ctx.send("Use this command at the bump channel")
return
if not action.casefold() == "bump":
return
if not disboard.status == discord.Status.online:
await ctx.send(embed=(discord.Embed(color=discord.Colour.red,description=(f"Whoa {disboard.mention} appears to be offline right now!\nI'll monitor the bump bot's status and notify everyone when it comes back online."))))
return
else :
await ctx.send("thanks for bumping,disboard will be back in two hours to be bumped:)")
await ctx.channel.set_permissions(disboard, view_channel =False)
lock_disboard_Out_for_two_hours.start()
return
@tasks.loop(hours=2)
async def lock_disboard_Out_for_two_hours():
guild =client.get_guild(844231449014960160)
disband_role=discord.utils.get(guild.roles, name="DISBOARD")
bump_role=discord.utils.get(guild.roles, name="Bumpers")
channel=guild.get_channel(852646981759270972)
await channel.set_permissions(disband_role, view_channel = True)
await channel.send(f"Discord is back, {bump_role.mention} come bump the server!")
lock_disboard_Out_for_two_hours.cancel()
有没有更好的方法来做到这一点,或者我该怎么做才能使这项工作,因为循环 task.loop() 首先运行,然后等待 2 小时,然后再次运行,但我只希望它在 2 之后运行小时,我希望有一种简单的方法可以让这个命令工作。
【问题讨论】:
标签: python discord.py