简体   繁体   English

在 Python 中编程 Discord 机器人 - 我将如何制作它以便我的静音命令是定时的?

[英]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.

相关问题 在 Python 中编程 Discord 机器人 - 如何发出静音命令? - Programming a Discord bot in Python- How do I make a mute command? 用 Python 编写一个 Discord 机器人 - 我有一个 meme 命令,我该如何制作它才能减少两次显示相同 meme 的机会? - Programming a Discord bot in Python- I have a meme command, how do I make it so there is less of a chance to show the same meme twice? 在 Python 中编程 Discord 机器人 - 如何发出踢命令? - Programming a Discord bot in Python- How do I make a kick command? 用 Python 编写 Discord 机器人 - 如何让机器人对自己的消息做出反应? - Programming a Discord bot in Python- How do I make the bot react to its own message? 用 Python 编写 Discord 机器人 - 如何让机器人 ping @everyone? - Programming a Discord bot in Python- How do I make the bot ping @everyone? 在 Python 中编程 Discord 机器人 - 如何让机器人重复图像? - Programming a Discord bot in Python- How do I make the bot repeat an image? 在 Python 中编程 Discord 机器人 - 如何让机器人从 subreddit 发送随机文本组? - Programming a Discord bot in Python- How do I make the bot send a random group of text from a subreddit? 在 Python 中编程 Discord 机器人 - 如何使机器人将命令限制到某个服务器? - Programming a Discord bot in Python- How do I make the bot restrict commands to a certain server? 在 Python 中编程 Discord 机器人 - 如何使其过滤垃圾邮件? - Programming a Discord bot in Python- How do I make it filter spam? 用 Python 编写 Discord 机器人 - 如何在嵌入中缩进? - Programming a Discord bot in Python- How do I indent in embeds?
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM