python - 我需要帮助在 discord py 中创建 discord py temp 静音命令
问题描述
我让我的不和谐机器人有一个静音命令,但你必须在以后自己取消静音用户,我想要另一个名为“tempmute”的命令,它将成员静音一段时间/小时/或几天,这个到目前为止我的代码是什么,我该如何制作一个临时静音命令?
#mute command
@client.command()
@commands.has_permissions(kick_members=True)
async def mute(ctx, member: discord.Member=None):
if not member:
await ctx.send("Who do you want me to mute?")
return
role = discord.utils.get(ctx.guild.roles, name="muted")
await member.add_roles(role)
await ctx.send("ok I did it")
解决方案
与您赋予他们静音的角色类似,只需添加另一个参数以计算您希望他们在几秒钟内静音的时间。然后,您可以在删除该角色之前使用 await asyncio.sleep(mute_time) 。
代码将类似于:
import asyncio
#mute command
@client.command()
@commands.has_permissions(kick_members=True)
async def mute(ctx, member: discord.Member=None, mute_time : int):
if not member:
await ctx.send("Who do you want me to mute?")
return
role = discord.utils.get(ctx.guild.roles, name="muted")
await member.add_roles(role)
await ctx.send("ok I did it")
await asyncio.sleep(mute_time)
await member.remove_roles(role)
await ctx.send("ok times up")
推荐阅读
- php - 删除 Mpdf v7 中的边距
- c# - 在 GetCallbackChannel 上获取 InvalidCastException
- azure - 如何使用逻辑应用以编程方式在 Azure AD 中注册应用?
- terraform - terraform state 是否为不同的配置文件保存状态?
- haskell - 我可以证明 (forall x. Coercible (ax) (bx)) 暗示 Coercible ab 吗?
- python - 通过管理员控制上传图片
- python - 只强制执行模块文档字符串?
- r - 如何在一列中查找重复项并将它们标记在新列中,具体取决于使用 R 在第三列中的日期顺序
- java - 如何使用 ContentResolver 删除
- c# - 有没有办法可以将初始化值递减为用户输入值?