我需要在Discord py中制作Discord py temp Mutute命令的帮助 [英] I need help making a discord py temp mute command in discord py

查看:66
本文介绍了我需要在Discord py中制作Discord py temp Mutute命令的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我让我的discord机器人有一个静音命令,但是您必须稍后自己取消静音,我想使用另一个名为 tempmute的命令将某个成员静音几分钟/小时/或者天,到目前为止,这是我的代码,我将如何从中发出临时静音命令?

I got my discord bot to have a mute command but you have to unmute the user yourself at a later time, I want to have another command called "tempmute" that mutes a member for a certain number of minutes/hours/ or days, this is my code so far, how would I make a temp mute command out of this?

#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)。

Similar to how you gave them a role to mute them, just add another parameter to take in how long you want them to be muted in seconds. Then you can use await asyncio.sleep(mute_time) before removing that role.

代码如下:

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")

这篇关于我需要在Discord py中制作Discord py temp Mutute命令的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆