【发布时间】:2021-06-23 12:19:54
【问题描述】:
我有这个代码让我的不和谐机器人暂时静音:
@bot.command()
async def tempmute(ctx, member: discord.Member, time: int, d, *, reason=None):
guild = ctx.guild
mutedRole = discord.utils.get(guild.roles, name="Muted")
if not mutedRole:
mutedRole = await guild.create_role(name="Muted")
for channel in guild.channels:
await channel.set_permissions(mutedRole, speak=False, send_messages=False, read_message_history=True)
for role in guild.roles:
if role.name == "Muted":
await member.add_roles(role)
embed = discord.Embed(title="TempMuted!", description=f"{member.mention} has been tempmuted.", colour=discord.Colour.light_gray())
embed.add_field(name="Reason:", value=reason, inline=False)
embed.add_field(name="Time for the mute:", value=f"{time}{d}", inline=False)
await ctx.send(embed=embed)
if d == "s":
await asyncio.sleep(time)
if d == "m":
await asyncio.sleep(time*60)
if d == "h":
await asyncio.sleep(time*60*60)
if d == "d":
await asyncio.sleep(time*60*60*24)
await member.remove_roles(role)
embed = discord.Embed(title="Unmute (temp mute expired) ", description=f"Unmuted -{member.mention} ", colour=discord.Colour.light_gray())
await ctx.send(embed=embed)
return
但是,我的机器人每 12-24 小时会自行重新启动,如果有人在机器人重新启动时当前处于临时静音状态,他们永远不会取消静音,因为机器人忘记了它曾经静音过他们,所以他们保持静音,直到我手动取消静音他们。有没有一种方法可以让机器人仍然记得取消静音,即使机器人在静音期间重新启动?如果是这样,请你告诉我我应该在我的代码中添加什么。谢谢!
注意:如果有帮助,我会通过 GitHub 和 Heroku 托管我的机器人,以防万一。
【问题讨论】:
标签: discord.py