gpt4 book ai didi

python - 我需要帮助在 discord py 中制作一个 discord py temp mute 命令

转载 作者:行者123 更新时间:2023-12-03 16:36:04 24 4
gpt4 key购买 nike

我让我的不和谐机器人有一个静音命令,但你必须在稍后自己取消静音用户,我想要另一个名为“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")

关于python - 我需要帮助在 discord py 中制作一个 discord py temp mute 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60903218/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com