[英]Programming a Discord bot in Python- How would I make it so my mute command is timed?
So I have a mute commmand using the following code:所以我有一个使用以下代码的静音命令:
@client.command(pass_context = True)
async def mute(ctx, member: discord.Member):
role = discord.utils.get(member.guild.roles, name='Muted')
await member.add_roles(role)
embed=discord.Embed(title="User Muted!", description="**{0}** was muted by **{1}**!".format(member, ctx.message.author), color=random.choice(colors))
await ctx.send(embed=embed)
It works fine, but I want to make it so you can specify how long they will be muted for.它工作正常,但我想这样做,以便您可以指定它们将被静音多长时间。 Not quite sure how to do that.不太确定该怎么做。
I am new to programming, so any insight would be greatly appreciated.我是编程新手,所以任何见解都将不胜感激。
Add a await asyncio.sleep()
for the specified time and then remove the role.添加一个await asyncio.sleep()
指定的时间,然后删除角色。 Make sure to import asyncio
.确保import asyncio
。
Although await asyncio.sleep()
is an option, I would not recommend it.虽然await asyncio.sleep()
是一个选项,但我不推荐它。 The time is saved in the cache and if/when the bot restarts or shuts down, the cache will be wiped the people will stay muted forever.时间保存在缓存中,如果/当机器人重新启动或关闭时,缓存将被擦除,人们将永远保持沉默。 In my opinion the best way to deal with that is to use a database where you store the time when people should be unmuted.在我看来,处理这个问题的最好方法是使用一个数据库来存储人们应该取消静音的时间。 Menu Docs has a really good tutorial on that, I suggest watching it to get more info. Menu Docs 有一个非常好的教程,我建议观看它以获取更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.